Python 如何在pandas中按列表删除行
现在我有了dataframe和listPython 如何在pandas中按列表删除行,python,pandas,dataframe,Python,Pandas,Dataframe,现在我有了dataframe和list A B 1 a 2 b 3 c 4 d 5 e list=[a,b,c] 我想删除df.B中引用列表的行 我想在下面谈谈 A B 4 d 5 e 如何获得此结果?您可以通过~使用反转遮罩 我认为list在python中不是个好名字,最好是L,因为list是码字,如果赋值变量,则覆盖它: L= ['a','b','c'] print (df[~df.B.isin(L)]) A B 3 4 d 4 5 e
A B
1 a
2 b
3 c
4 d
5 e
list=[a,b,c]
我想删除df.B中引用列表的行
我想在下面谈谈
A B
4 d
5 e
如何获得此结果?您可以通过~
使用反转遮罩
我认为list
在python
中不是个好名字,最好是L
,因为list
是码字,如果赋值变量,则覆盖它:
L= ['a','b','c']
print (df[~df.B.isin(L)])
A B
3 4 d
4 5 e