如何搜索字符以及使用pandas.Series.str.contains [英] how to search character plus using pandas.Series.str.contains

查看:113
本文介绍了如何搜索字符以及使用pandas.Series.str.contains的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在熊猫数据框列中使用"pandas.Series.str.contains"搜索字符"+".我尝试过

How do I search the character '+' using "pandas.Series.str.contains" in a pandas dataframe column. I tried

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

错误:没什么可重复的

推荐答案

请使用反斜杠berofe plus:

Please use backslash berofe plus:

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

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

结果:

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

这篇关于如何搜索字符以及使用pandas.Series.str.contains的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆