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

Ani*_*l K 3 python pandas

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

df_noplus = df[df['column1'].str.contains('+',case=False)]
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误

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

错误:没有可重复的内容

Ale*_*mov 6

请在前面加上反斜杠:

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

df['a'].str.contains('\+')
Run Code Online (Sandbox Code Playgroud)

结果:

0     True
1     True
2    False
Name: a, dtype: bool
Run Code Online (Sandbox Code Playgroud)