如何使用pandas.Series.str.contains搜索字符

时间:2017-05-17 09:46:18

标签: python pandas

如何在pandas dataframe列中使用“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))

错误:无需重复

1 个答案:

答案 0 :(得分:1)

请使用反斜杠berofe plus:

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

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

结果:

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