Drop rows with all zeros in pandas data frame

前端 未结 13 1216
礼貌的吻别
礼貌的吻别 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:27

    Replace the zeros with nan and then drop the rows with all entries as nan. After that replace nan with zeros.

    import numpy as np
    df = df.replace(0, np.nan)
    df = df.dropna(how='all', axis=0)
    df = df.replace(np.nan, 0)
    

提交回复
热议问题