我想从一个pandas DataFrame中删除所有行,该pandas的'Beguenstigter/Zahlungspflichtiger‘列中的条目包含在一个列表(或集合)中。amazon
这里只是一个字符串列表。
我在这个网站上研究后的最大努力是这样的:
extract_df = extract_df.drop(extract_df[extract_df['Beguenstigter/Zahlungspflichtiger'] in amazon].index)
print(extract_df)
但它不仅笨重且不美观,还会抛出错误:
如果我给亚马逊做一个套装,我会得到
TypeError: 'Series' objects are mutable, thus they cannot be hashed
如果我把它作为列表保存,我会得到
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
有人能给我解释一下为什么这个命令会产生这些错误吗?正确的命令是什么?我在这里看到的许多关于这个主题的帖子似乎已经被弃用了,到目前为止还没有解决方案。谢谢你的帮助!
发布于 2021-04-18 09:11:46
试试这个:( ~
的Alt + 126
,它代表子设置时的逻辑否定) extract_df[~extract_df['Beguenstigter/Zahlungspflichtiger'].isin(amazon)]
https://stackoverflow.com/questions/67146677
复制相似问题