I am dropping rows from a PANDAS dataframe when some of its columns have 0 value. I got the output by using the below code, but I hope we can do the same with less code — perhaps in a single line.
df:
A B C
0 1 2 5
1 4 4 0
2 6 8 4
3 0 4 2
My code:
drop_A=df.index[df["A"] == 0].tolist()
drop_B=df.index[df["C"] == 0].tolist()
c=drop_A+drop_B
df=df.drop(df.index[c])
[out]
A B C
0 1 2 5
2 6 8 4