带有 OR 运算符的 DataFrame UserWarning
DataFrame UserWarning with OR operator
Python 3.6。我有 DataFrame 警告:
UserWarning: This pattern has match groups. To actually get the groups, use str.extract.
使用这种模式:
laDataTemps.loc[laDataTemps['texte'].str.contains(r'\b(word1|word2)\b', regex=True)]
或者,如果我删除括号以避免分组,它的含义就不一样了。关于如何更改模式以删除警告的任何想法?谢谢!
使用 non-capturing group:
laDataTemps.loc[laDataTemps['texte'].str.contains(r'\b(?:word1|word2)\b', regex=True)]
^^^
通过这种方式,您不会捕获任何文本并保留模式的语义,其中单词边界应用于每个备选方案的两端。
Python 3.6。我有 DataFrame 警告:
UserWarning: This pattern has match groups. To actually get the groups, use str.extract.
使用这种模式:
laDataTemps.loc[laDataTemps['texte'].str.contains(r'\b(word1|word2)\b', regex=True)]
或者,如果我删除括号以避免分组,它的含义就不一样了。关于如何更改模式以删除警告的任何想法?谢谢!
使用 non-capturing group:
laDataTemps.loc[laDataTemps['texte'].str.contains(r'\b(?:word1|word2)\b', regex=True)]
^^^
通过这种方式,您不会捕获任何文本并保留模式的语义,其中单词边界应用于每个备选方案的两端。