简体   繁体   English

如果一列的字符串包含 pandas dataframe 中另一列的单词,如何删除整行

[英]How to drop entire row if string of one column contains the word from another column in pandas dataframe

Dataframe contain columns called "product_description" and "manufacturer". Dataframe 包含名为“product_description”和“manufacturer”的列。 I need to remove all rows where 'product_description' has 'manufacturer' in it.我需要删除“product_description”中包含“manufacturer”的所有行。

I tried this code:我试过这段代码:

df[~df.product_description.str.contains(df.manufacturer)]

and it gave me error它给了我错误

TypeError: 'Series' objects are mutable, thus they cannot be hashed

Is there any other way to do it?还有其他方法吗?
Very much appreciate for any help!非常感谢您的帮助!

If need test all values from column manufacturer per each value of column product_description use join with |如果需要根据列product_description的每个值测试列manufacturer的所有值,请使用join with | for regex or :对于正则表达式or

df[~df.product_description.str.contains('|'.join(data.manufacturer))]

Or if need test per rows:或者如果需要每行测试:

df[df.apply(lambda x: x.product_description not in x.manufacturer, axis=1)]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果熊猫列中只有单词,如何在熊猫数据框中删除一行 - How to drop a row in pandas dataframe if there is only word in a pandas column 如何在整个Pandas数据帧中搜索字符串,并获取包含该字符串的列的名称? - How to search entire Pandas dataframe for a string and get the name of the column that contains it? Pandas 如果列包含字符串,则从另一列获取唯一值并从 dataframe 中删除行 - Pandas if colum contains string then get unique value from another column and drop rows from dataframe 熊猫-检查一个数据帧中的字符串列是否包含来自另一个数据帧的一对字符串 - Pandas - check if a string column in one dataframe contains a pair of strings from another dataframe 将最后一个字从一列移动到下一行 Pandas Dataframe - Move the last word from one column to next row in Pandas Dataframe pandas dataframe 如何判断一行的字符串值是否包含在同一列的另一行的字符串值中 - How to check if a string value of one row is contained in the string value of another row in the same column in pandas dataframe 熊猫如何将一个数据框的一列作为一行添加到另一数据框 - pandas how to add a column of one dataframe as a row into another dataframe 如何在一个 Pandas 数据帧列中搜索字符串作为另一个数据帧中的子字符串 - How to search a string in one pandas dataframe column as a substring in another dataframe 如何检查 dataframe 列是否包含来自另一个 dataframe 列的字符串并返回 python Z3A0524F883225EFFA94 中的相邻单元格 - How do I check if dataframe column contains a string from another dataframe column and return adjacent cell in python pandas? 如何将 dataframe 中的每一列与另一个 dataframe pandas 的行相乘? - How to multiply each column in a dataframe with a row from another dataframe pandas?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM