Dataframe 包含名为“product_description”和“manufacturer”的列。我需要删除“product_description”中包含“manufacturer”的所有行。
我试过这个代码:
df[~df.product_description.str.contains(df.manufacturer)]
它给了我错误
TypeError: 'Series' objects are mutable, thus they cannot be hashed
还有其他方法吗?
非常感谢您的帮助!
答案 0 :(得分:3)
如果需要根据列 manufacturer
的每个值测试列 product_description
中的所有值,请使用 join
和 |
用于正则表达式 or
:
df[~df.product_description.str.contains('|'.join(data.manufacturer))]
或者如果需要每行测试:
df[df.apply(lambda x: x.product_description not in x.manufacturer, axis=1)]