Editor

Remove Duplicate Emails

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

Remove rows with duplicate 'email' values, keeping the first occurrence. Print the remaining emails as a list.

import pandas as pd
df = pd.DataFrame({
'email': ['a@test.com', 'b@test.com', 'a@test.com', 'c@test.com', 'b@test.com'],
'name': ['Alice', 'Bob', 'Alice2', 'Charlie', 'Bob2']
})
# Remove duplicate emails, keep first

More Pandas Data Cleaning exercises

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