【问题标题】:DataFrame UserWarning with OR operator [duplicate]带有 OR 运算符的 DataFrame UserWarning [重复]
【发布时间】:2018-09-06 03:12:05
【问题描述】:

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)]

或者,如果我删除括号以避免分组,它的含义就不一样了。关于如何更改模式以删除警告的任何想法?谢谢!

【问题讨论】:

标签: python regex python-3.x spark-dataframe


【解决方案1】:

使用non-capturing group

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

这样,您不会捕获任何文本并保持模式的语义,其中单词边界应用于每个备选方案的两端。

【讨论】:

  • 完成,抱歉我等了 5 分钟延迟后忘记了
猜你喜欢
  • 2020-05-21
  • 2017-03-20
  • 2018-12-28
  • 2019-12-31
  • 2018-07-22
  • 2021-03-14
  • 2015-10-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多