[英]How to drop a row in pandas dataframe if there is only word in a pandas column
[英]How to drop entire row if string of one column contains the word from another column in pandas dataframe
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
還有其他方法嗎?
非常感謝您的幫助!
如果需要根據列product_description
的每個值測試列manufacturer
的所有值,請使用join
with |
對於正則表達式or
:
df[~df.product_description.str.contains('|'.join(data.manufacturer))]
或者如果需要每行測試:
df[df.apply(lambda x: x.product_description not in x.manufacturer, axis=1)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.