Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ricgu8086
Last active June 23, 2019 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricgu8086/e30360e44e5c0dd54d28256424eb9f91 to your computer and use it in GitHub Desktop.
Save ricgu8086/e30360e44e5c0dd54d28256424eb9f91 to your computer and use it in GitHub Desktop.
A function to plot percentage of nulls in a dataframe (using seaborn and matplotlib)
def plot_nulls(dataframe):
def null_perc(dataframe):
return 100*dataframe.isnull().sum()/len(dataframe)
nulls = null_perc(dataframe)
plt.figure(1, figsize=(5,20)) # Customize this if needed
ax = sns.barplot(x=nulls, y=list(range(len(nulls))), orient='h', color="blue")
_ = plt.yticks(plt.yticks()[0], nulls.index)
ax.xaxis.set_ticks_position('top')
_ = plt.title("Null percentage (lower is better)", fontsize=15, pad=30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment