Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在pandas中按列表删除行_Python_Pandas_Dataframe - Fatal编程技术网

Python 如何在pandas中按列表删除行

Python 如何在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

现在我有了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