简体   繁体   English

根据列中特定字符“+”的存在过滤 dataframe 的行

[英]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.

相关问题 How to filter the rows of a dataframe based on the presence of the column values in a separate dataframe and append columns from the second dataframe - How to filter the rows of a dataframe based on the presence of the column values in a separate dataframe and append columns from the second dataframe 如何使用 Google 表格根据特定列中特定字符的存在从行中提取数据? - How can I pull data from rows based on the presence of a specific character in a specific column with Google Sheets? 根据特定列或列中是否存在空值,从DataFrame中选择行 - Select rows from a DataFrame based on presence of null value in specific column or columns 根据特定列中存在的NaN在python数据框中创建一个新列 - Create a new column in python dataframe based on the presence of NaN in a specific column Python:基于特定字符的存在在列中进行条件拆分 - Python: conditional splitting in column based on presence of a specific character 根据列中特定值的计数条件过滤掉火花 dataframe 的行 [pyspark 中的 spark.sql 语法] - filter out rows of a spark dataframe based on a count condition of specific value in a column [spark.sql syntax in pyspark] 根据另一列中是否存在值,将字符串有条件地追加到Pandas数据框中的行 - Conditionally append string to rows in a Pandas dataframe based on presence of values in another column 根据一列过滤熊猫数据框:保留所有行(如果值是该列) - Filter pandas dataframe based on a column: keep all rows if a value is that column 如何根据Python中列的行中列表中的值过滤数据帧? - How to filter a dataframe based on the values present in the list in the rows of a column in Python? 根据 dataframe 中列表列列表的条件过滤和删除行 - Filter and Drop rows based on a condition for a list of list column in dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM