Created
May 25, 2020 02:07
-
-
Save ecdedios/f23de95d813b2e1626de2c72796bc29d to your computer and use it in GitHub Desktop.
A function to show total number of missing values and their percentages.
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
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}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one