Examples
A pattern with two groups will return a DataFrame with two columns. Non-matches will be NaN.
import numpy as np
import pandas as pd
s = pd.Series(['a3', 'b4', 'c5'])
s.str.extract(r'([ab])(\d)')
A pattern may contain optional groups.
s.str.extract(r'([ab])?(\d)')
Named groups will become column names in the result.
s.str.extract(r'(?P<letter>[ab])(?P<digit>\d)')
A pattern with one group will return a DataFrame with one column if expand=True.
s.str.extract(r'[ab](\d)', expand=True)
A pattern with one group will return a Series if expand=False.
s.str.extract(r'[ab](\d)', expand=False)