Editor

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 lesson

Count 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

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz