Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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