Skip to content

Instantly share code, notes, and snippets.

@qiuyujx
Last active September 27, 2020 11:38
Show Gist options
  • Save qiuyujx/c67aad7ba8bd739035310939582c2b54 to your computer and use it in GitHub Desktop.
Save qiuyujx/c67aad7ba8bd739035310939582c2b54 to your computer and use it in GitHub Desktop.
Calculate Data Missing Percentage
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