【问题标题】:how to search character plus using pandas.Series.str.contains如何使用 pandas.Series.str.contains 搜索字符加
【发布时间】:2017-05-17 17:49:34
【问题描述】:

如何在 pandas 数据框列中使用“pandas.Series.str.contains”搜索字符“+”。我试过了

df_noplus = df[df['column1'].str.contains('+',case=False)]

它给了我一个错误

  File "/home/anil/anaconda3/lib/python3.5/sre_parse.py", line 638, in _parse
    source.tell() - here + len(this))

错误:无需重复

【问题讨论】:

  • df_noplus = df[df['column1'].str.contains('\+',case=False)] 工作吗?
  • 是的,放一个斜线

标签: python pandas


【解决方案1】:

请使用反斜杠加号:

df = pd.DataFrame({'a': ['+1','+2','-4']})

df['a'].str.contains('\+')

结果:

0     True
1     True
2    False
Name: a, dtype: bool

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多