python - pandas delete the 0 appears most times -
i have dataframe this:
a b c d 1 0 0 0 0 1 0 7 5 2 0 4 6 3 0 0 0 0 8 8 0 7 7 7 0 0 0 1
1: fow each row, if counts of 0 >90% of column counts(in case: mean: 0.9*4 ), delete row.
2: fow each column, if counts of 0 >90% of row counts(in case: mean: 0.9*7 ), delete column.
i guess want like:
mask_rows = pd.dataframe.sum(df == 0, axis=1) > 0.9*len(df.columns) mask_cols = pd.dataframe.sum(df == 0, axis=0) > 0.9*len(df.columns)
this creates mask following interpretation of question...
Comments
Post a Comment