[英]Filter rows of a dataframe based on presence of specific character '+' in the column
I have data frame like this:我有这样的数据框:
id : Name
0 : one
1 : one + two
2 : two
3 : two + three + four
I want to filter rows from this dataframe where name contains '+' and save it to another dataframe. I tried:我想从这个 dataframe 中过滤名称包含“+”的行,并将其保存到另一个 dataframe。我试过:
df[df.Name.str.contains("+")]
but i'm gettin error:但我开始出错了:
nothting to repeat at position 0
Any help would be appreciated...Thanks任何帮助将不胜感激......谢谢
Looking at the documentation of the str.contains
method, it assumes that the string you are passing is a regexp by default.查看
str.contains
方法的文档,它假定您传递的字符串默认是正则表达式。
Therefore, you can either escape the plus character: "\+"
or pass the argument regex=False
to the method:因此,您可以转义加号字符:
"\+"
或将参数regex=False
传递给该方法:
df[df.Name.str.contains("\+")]
df[df.Name.str.contains("+", regex=False)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.