Editor

Standardize Yes/No Responses

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

Standardize the 'answer' column so that all variations of yes ('Yes', 'Y', 'y') become 'yes' and all variations of no ('No', 'N', 'n') become 'no'. Print the cleaned answers as a list.

import pandas as pd
df = pd.DataFrame({
'answer': ['Yes', 'N', 'y', 'No', 'Y', 'n']
})
# Standardize the answer column

More Pandas Data Cleaning exercises

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