Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.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 删除任何行中有0的列dataframe_Python_Pandas_Dataframe - Fatal编程技术网

Python 删除任何行中有0的列dataframe

Python 删除任何行中有0的列dataframe,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个这样的数据帧 a b c 1. 0. 6 2. 4. 7 0. 8. 8 我想删除任何一行中有0的所有列,在这种情况下,我只想保留c列 我试过使用df.loc[:,(df!=0)],但不起作用。用于测试的所有值都不是0: df = df.loc[:, (df != 0).all()] print (df) c 0 6 1 7 2 8 用于测试所有值不是0: df = df.loc[:, (df != 0).all()] print (d

我有一个这样的数据帧


   a  b  c 

   1. 0. 6
   2. 4. 7
   0. 8. 8

我想删除任何一行中有0的所有列,在这种情况下,我只想保留c列

我试过使用
df.loc[:,(df!=0)]
,但不起作用。

用于测试的所有值都不是
0

df = df.loc[:, (df != 0).all()]
print (df)
   c
0  6
1  7
2  8
用于测试所有值不是
0

df = df.loc[:, (df != 0).all()]
print (df)
   c
0  6
1  7
2  8