2

Python 3.6. I have the DataFrame warning : UserWarning: This pattern has match groups. To actually get the groups, use str.extract. with this pattern : laDataTemps.loc[laDataTemps['texte'].str.contains(r'\b(word1|word2)\b', regex=True)]

Or, if i remove parenthesis to avoid groups, it won't have the same meaning. Any idea on how i could change the pattern to remove the warning ? Thanks !

TmSmth
  • 450
  • 5
  • 31
  • Does this answer your question? [Python: UserWarning: This pattern has match groups. To actually get the groups, use str.extract](https://stackoverflow.com/questions/39901550/python-userwarning-this-pattern-has-match-groups-to-actually-get-the-groups) – krassowski Feb 28 '20 at 15:05

1 Answers1

4

Use a non-capturing group:

laDataTemps.loc[laDataTemps['texte'].str.contains(r'\b(?:word1|word2)\b', regex=True)]
                                                      ^^^

This way, you do not capture any text and keep the semantics of the pattern where word boundaries are applied to both ends of each alternative.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563