Count Missing Values
Intermediate · Write the code · from Pandas Data Cleaning: Missing Values, Duplicates, and Outliers
From the lesson: Pandas Data Cleaning: Missing Values, Duplicates, and Outliers
You just got a dataset from a survey. Some people skipped questions, one person typed "N/A" instead of leaving a field blank, there are three duplicate entries, and someone claims to be 900 years old. Welcome to real-world data.
Read the lessonCount the total number of missing values across the entire DataFrame and print the result as an integer.
import pandas as pd
df = pd.DataFrame({
'name': ['Alice', None, 'Charlie', 'Diana'],
'age': [28, 34, None, 45],
'city': [None, 'LA', 'NYC', None]
})
# Count total missing values
More Pandas Data Cleaning exercises
- Fill Missing Scores with the MeanIntermediate
- Drop Rows Missing a NameIntermediate
- Remove Duplicate EmailsIntermediate
- Standardize Yes/No ResponsesIntermediate
- Predict the Output: astypeIntermediate
- Remove Outlier AgesIntermediate
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz