How to drop column according to NAN percentage for dataframe?

You can use isnull with mean for threshold and then remove columns by boolean indexing with loc (because remove columns), also need invert condition – so <.8 means remove all columns >=0.8: df = df.loc[:, df.isnull().mean() < .8] Sample: np.random.seed(100) df = pd.DataFrame(np.random.random((100,5)), columns=list(‘ABCDE’)) df.loc[:80, ‘A’] = np.nan df.loc[:5, ‘C’] = np.nan df.loc[20:, ‘D’] = … Read more