data_cleaning_202001
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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').plot.bar(x='index', y='num_missing') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment