Fill Missing Scores with the Mean
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 lessonFill missing values in the 'score' column with the column's mean. Print the score column as a list. The mean should be computed before filling.
import pandas as pd
df = pd.DataFrame({
'name': ['Alice', 'Bob', 'Charlie', 'Diana'],
'score': [80.0, None, 90.0, None]
})
# Fill missing scores with the mean
More Pandas Data Cleaning exercises
- Count Missing ValuesIntermediate
- 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