Q:

Select column by percentage of non zero values

I have a big sparse dataframe and I'd like to remove automatically the columns (the column keys/names are dynamic, so in principle I don't know the column number and the naming) with a number of non zero element below a certain percentage of the total row number.   
Thank you!

A:

Pandas has a dropna function, which has a thresh parameter. Simply set that to the number of non-zero values you need to keep. So
df.dropna(thres=int(len(df)*0.8), axis=1)

Will drop columns where less than 80% of the rows are complete.

