Search code examples
pythonseriestext-extraction

Pandas Series: Extract text between parenthesis including them


How can I include the parenthesis when I extract text from a pandas series?

my_series.str.extract('\((.*)\)')

Solution

  • If you want to have the parenthesis captured inside the capture group, you need to put the escaped parenthesis inside the group like this :

    my_series.str.extract('(\(.*\))')