Find the missing data percentage and count in pandas
Milind Soorya / October 13, 2022
1 min read
I use this piece of code almost daily. So, thought it might be a good idea to share.
Use the below code to display the missing data statistics.
df
—Is the input dataset with missing values
missing_number
—This gives the sum of missing values in the data frame.
missing_percent
—This gives the percentage of missing values in the data frame.
missing_number = df.isnull().sum()
missing_percent = df.isnull().sum() * 100 / len(df)
missing_value_df = pd.DataFrame({'column_name': df.columns,
'missing_count': missing_number,
'percent_missing': missing_percent})
missing_value_df = missing_value_df.reset_index(drop=True)
missing_value_df.sort_values('percent_missing')
You might also like:-
- Mushroom dataset analysis and classification in python
- How To Set Up Jupyter Notebook with Python 3 on Ubuntu 20.04
- How to use python virtual environment with conda