I have a dataframe that has a lot of 0, like the df example below. I would like to remove any row that has 0 in three or more columns, for example, the Resultdf example.
Below is a script to delete all entries, all 0
df = df[(df.T != 0).any()]
Is there a way to change it so that it deletes records, all 0, or having three or more columns with 0? Or is there another way to do this?
print df:
ind_key prtCnt fldCnt TmCnt bmCnt
1 0 0 0 0
2 2 0 0 3
3 0 1 0 0
4 0 1 1 0
print Resultdf:
ind_key prtCnt fldCnt TmCnt bmCnt
2 2 0 0 3
4 0 1 1 0
source
share