Drop rows with all zeros in pandas data frame

One-liner. No transpose needed:

df.loc[~(df==0).all(axis=1)]

And for those who like symmetry, this also works…

df.loc[(df!=0).any(axis=1)]

Leave a Comment