Skip to content

Instantly share code, notes, and snippets.

@austinbrian
Last active December 31, 2018 20:29
Show Gist options
  • Save austinbrian/6c95fb800f40c82ed010830acec4120b to your computer and use it in GitHub Desktop.
Save austinbrian/6c95fb800f40c82ed010830acec4120b to your computer and use it in GitHub Desktop.
Check df nulls
def check_nulls(df):
df_cols = df.columns
col_counts = [df[col].count() for col in df_cols]
col_lens = [len(df[col]) for col in df_cols]
cdf = pd.DataFrame(index = df_cols,
data = {'Values':col_counts,
'Total': col_lens})
cdf['% N/A'] = 1-(cdf['Values']/cdf.Total)
cdf['% N/A'] = cdf['% N/A'].map('{:.1%}'.format) # formats as percentages
return cdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment