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.
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.
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