extract(self, pat: 'str', flags: 'int' = 0, expand: 'bool' = True) -> 'DataFrame | Series | Index'
For each subject string in the Series, extract groups from the first match of regular expression :None:None:`pat`
.
Regular expression pattern with capturing groups.
Flags from the re
module, e.g. re.IGNORECASE
, that modify regular expression matching for things like case, spaces, etc. For more details, see re
.
If True, return DataFrame with one column per capture group. If False, return a Series/Index if there is one capture group or DataFrame if there are multiple capture groups.
A DataFrame with one row for each subject string, and one column for each group. Any capture group names in regular expression pat will be used for column names; otherwise capture group numbers will be used. The dtype of each result column is always object, even when no match is found. If expand=False
and pat has only one capture group, then return a Series (if subject is a Series) or Index (if subject is an Index).
Extract capture groups in the regex :None:None:`pat`
as columns in a DataFrame.
extractall
Returns all matches (not just the first match).
A pattern with two groups will return a DataFrame with two columns. Non-matches will be NaN.
This example is valid syntax, but we were not able to check execution>>> s = pd.Series(['a1', 'b2', 'c3'])
... s.str.extract(r'([ab])(\d)') 0 1 0 a 1 1 b 2 2 NaN NaN
A pattern may contain optional groups.
This example is valid syntax, but we were not able to check execution>>> s.str.extract(r'([ab])?(\d)') 0 1 0 a 1 1 b 2 2 NaN 3
Named groups will become column names in the result.
This example is valid syntax, but we were not able to check execution>>> s.str.extract(r'(?P<letter>[ab])(?P<digit>\d)') letter digit 0 a 1 1 b 2 2 NaN NaN
A pattern with one group will return a DataFrame with one column if expand=True.
This example is valid syntax, but we were not able to check execution>>> s.str.extract(r'[ab](\d)', expand=True) 0 0 1 1 2 2 NaN
A pattern with one group will return a Series if expand=False.
This example is valid syntax, but we were not able to check execution>>> s.str.extract(r'[ab](\d)', expand=False) 0 1 1 2 2 NaN dtype: objectSee :
The following pages refer to to this document either explicitly or contain code examples using this.
pandas.core.strings.accessor.StringMethods.fullmatch
pandas.core.strings.accessor.StringMethods.extractall
pandas.core.strings.accessor.StringMethods.match
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them