Last active
September 27, 2020 11:38
-
-
Save qiuyujx/c67aad7ba8bd739035310939582c2b54 to your computer and use it in GitHub Desktop.
Calculate Data Missing Percentage
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 missing_pct(df): | |
# Calculate percentage of missing for each column | |
s_missing = df.isnull().sum() * 100 / df.shape[0] | |
# Convert the series back to data frame | |
df_missing = pd.DataFrame(s_missing).round(2) | |
# Reset and rename the index | |
df_missing = df_missing.reset_index().rename( | |
columns={ | |
'index':'Column', | |
0:'Missing_Percentage (%)' | |
} | |
) | |
# Sort the data frame | |
df_missing = df_missing.sort_values('Missing_Percentage (%)', ascending=False) | |
return df_missing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment