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