pandas.Series.str.extract

pandas 3.1.1 · Series and accessors · method

Capture groups from the first matching region in each string. Use parentheses in the regular expression to define output fields.

Call syntax

Series.str.extract(pat, flags=0, expand=True)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
pat Required
Positional or keyword
str

Specify the substring or regular expression to match.

flags Optional
Positional or keyword
Default 0
int

Pass regular-expression modifiers such as re.IGNORECASE.

expand Optional
Positional or keyword
Default True
bool

Choose whether to expand extracted pieces into separate columns.

Returns

DataFrame or Series or Index