Skip to content

Instantly share code, notes, and snippets.

@redpoint13
Created December 28, 2020 18:10
Show Gist options
  • Save redpoint13/51a97653ac152d3d80e92f289b601b2a to your computer and use it in GitHub Desktop.
Save redpoint13/51a97653ac152d3d80e92f289b601b2a to your computer and use it in GitHub Desktop.
missing value heatmap from pandas dataframe
import seaborn as sns
cols = df.columns[:30] # first 30 columns
colors = ['#000099', '#ffff00'] # specify the colours - yellow is missing. blue is not missing.
sns.heatmap(df[cols].isnull(), cmap=sns.color_palette(colors))
# if it's a larger dataset and the visualization takes too long can do this.
# % of missing.
for col in df.columns:
pct_missing = np.mean(df[col].isnull())
if pct_missing > 0.009:
print('{} - {}%'.format(col, round(pct_missing*100)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment