Skip to content

Instantly share code, notes, and snippets.

Last active January 27, 2020 16:33
What would you like to do?
# first create missing indicator for features with missing data
for col in df.columns:
missing = df[col].isnull()
num_missing = np.sum(missing)
if num_missing > 0:
print('created missing indicator for: {}'.format(col))
df['{}_ismissing'.format(col)] = missing
# then based on the indicator, plot the histogram of missing values
ismissing_cols = [col for col in df.columns if 'ismissing' in col]
df['num_missing'] = df[ismissing_cols].sum(axis=1)
df['num_missing'].value_counts().reset_index().sort_values(by='index')'index', y='num_missing')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment