Drop rows with all zeros in pandas data frame

前端 未结 13 1136
礼貌的吻别
礼貌的吻别 2020-11-27 11:57

I can use pandas dropna() functionality to remove rows with some or all columns set as NA\'s. Is there an equivalent function for drop

13条回答
  •  清酒与你
    2020-11-27 12:36

    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)]
    

提交回复
热议问题