Drop Rows Missing a Name
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 lessonDrop only the rows where the 'name' column is missing (don't drop rows that have missing values in other columns). Print the remaining names as a list.
import pandas as pd
df = pd.DataFrame({
'name': ['Alice', None, 'Charlie', None, 'Eve'],
'age': [28, 34, None, 45, 30]
})
# Drop rows where name is missing
More Pandas Data Cleaning exercises
- Count Missing ValuesIntermediate
- Fill Missing Scores with the MeanIntermediate
- 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