Skip to content

Instantly share code, notes, and snippets.

@aflansburg
Last active April 15, 2021 17:01
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 aflansburg/86884422abcd51090b7ebf4f83939a79 to your computer and use it in GitHub Desktop.
Save aflansburg/86884422abcd51090b7ebf4f83939a79 to your computer and use it in GitHub Desktop.
Tabular Null Value Check display Function for Pandas Dataframe
# Not my original function - looking for citation
def missing_check(df):
null_val_sum = df.isnull().sum()
total = df.isnull().sum().sort_values(ascending=False) # total null values
percent = (null_val_sum/df.isnull().count()).sort_values(ascending=False)
missing_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
return missing_data
'''
Example:
missing_data(df_with_nulls)
Output:
---------------------------
Total Percent
HDI for year 19590 0.704170
country 554 0.019914
sex 495 0.017793
population 459 0.016499
year 447 0.016068
gdp_per_capita ($) 440 0.015816
age 395 0.014198
suicides_no 390 0.014019
country-year 381 0.013695
suicides/100k pop 371 0.013336
gdp_for_year ($) 370 0.013300
generation 368 0.013228
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment