Skip to content

Instantly share code, notes, and snippets.

@Ailuropoda1864
Created September 6, 2017 16:12
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 Ailuropoda1864/edd045d8de389ab1b2862eec6c9a2532 to your computer and use it in GitHub Desktop.
Save Ailuropoda1864/edd045d8de389ab1b2862eec6c9a2532 to your computer and use it in GitHub Desktop.
This function prints the number and percentage of null values in each column in a pandas DataFrame.
import pandas as pd
def show_null(dataframe):
"""
prints the number and percentage of null values in each column
:param dataframe: a pandas DataFrame
:return: None
"""
if dataframe.isnull().sum().sum() == 0:
print('No null in the dataframe.')
else:
print('Number of nulls in each column:\n{}\n'.format(
dataframe.isnull().sum()
))
print('Percentage of nulls in each column:\n{}\n'.format(
dataframe.isnull().sum() / len(dataframe)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment