Skip to content

Instantly share code, notes, and snippets.

@ecdedios
Created May 25, 2020 02:07
Show Gist options
  • Save ecdedios/f23de95d813b2e1626de2c72796bc29d to your computer and use it in GitHub Desktop.
Save ecdedios/f23de95d813b2e1626de2c72796bc29d to your computer and use it in GitHub Desktop.
A function to show total number of missing values and their percentages.
def show_missing(df):
"""
Return the total missing values and the percentage of
missing values by column.
"""
null_count = df.isnull().sum()
null_percentage = (null_count / df.shape[0]) * 100
empty_count = pd.Series(((df == ' ') | (df == '')).sum())
empty_percentage = (empty_count / df.shape[0]) * 100
nan_count = pd.Series(((df == 'nan') | (df == 'NaN')).sum())
nan_percentage = (nan_count / df.shape[0]) * 100
return pd.DataFrame({'num_missing': null_count, 'missing_percentage': null_percentage,
'num_empty': empty_count, 'empty_percentage': empty_percentage,
'nan_count': nan_count, 'nan_percentage': nan_percentage})
@Eswar03
Copy link

Eswar03 commented Nov 10, 2020

Nice one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment