pandas 1.4.2

ParametersReturnsBackRef
extractall(self, pat, flags=0)

For each subject string in the Series, extract groups from all matches of regular expression pat. When each subject string in the Series has exactly one match, extractall(pat).xs(0, level='match') is the same as extract(pat).

Parameters

pat : str

Regular expression pattern with capturing groups.

flags : int, default 0 (no flags)

A re module flag, for example re.IGNORECASE . These allow to modify regular expression matching for things like case, spaces, etc. Multiple flags can be combined with the bitwise OR operator, for example re.IGNORECASE | re.MULTILINE .

Returns

DataFrame

A DataFrame with one row for each match, and one column for each group. Its rows have a MultiIndex with first levels that come from the subject Series . The last level is named 'match' and indexes the matches in each item of the Series . Any capture group names in regular expression pat will be used for column names; otherwise capture group numbers will be used.

Extract capture groups in the regex :None:None:`pat` as columns in DataFrame.

See Also

extract

Returns first match only (not all matches).

Examples

A pattern with one group will return a DataFrame with one column. Indices with no matches will not appear in the result.

This example is valid syntax, but we were not able to check execution
>>> s = pd.Series(["a1a2", "b1", "c1"], index=["A", "B", "C"])
... s.str.extractall(r"[ab](\d)") 0 match A 0 1 1 2 B 0 1

Capture group names are used for column names of the result.

This example is valid syntax, but we were not able to check execution
>>> s.str.extractall(r"[ab](?P<digit>\d)")
        digit
match
A 0         1
  1         2
B 0         1

A pattern with two groups will return a DataFrame with two columns.

This example is valid syntax, but we were not able to check execution
>>> s.str.extractall(r"(?P<letter>[ab])(?P<digit>\d)")
        letter digit
match
A 0          a     1
  1          a     2
B 0          b     1

Optional groups that do not match are NaN in the result.

This example is valid syntax, but we were not able to check execution
>>> s.str.extractall(r"(?P<letter>[ab])?(?P<digit>\d)")
        letter digit
match
A 0          a     1
  1          a     2
B 0          b     1
C 0        NaN     1
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.strings.accessor.StringMethods.findall pandas.core.strings.accessor.StringMethods.extract

Local connectivity graph

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


File: /pandas/core/strings/accessor.py#2566
type: <class 'function'>
Commit: