0

I have a dataframe like this


   a  b  c 

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

And I want to drop all columns which have 0 in any row, in this case I only want to keep column c

I have tried with df.loc[:, (df != 0)] but it doesn't work.

Nelly Louis
  • 157
  • 2
  • 8

1 Answers1

2

Use DataFrame.all for test all values are not 0:

df = df.loc[:, (df != 0).all()]
print (df)
   c
0  6
1  7
2  8
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252