2017-05-17 26 views
1

如何在熊猫数据框列中使用“pandas.Series.str.contains”搜索字符'+'。我试图如何搜索字符加使用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

does'df_noplus = df [df ['column1']。str.contains('\ +',case = False)]'work? – EdChum

+0

是的,把斜杠 – Satyadev

回答

1

请使用反斜杠berofe加:

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

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

结果:

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