Remove duplicate records
A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.
The task
The `leads` table has repeated emails. Keep only the most recent row for each email, which is the last one in the table. Keep the original row labels.
What this exercise teaches
Rows only count as duplicates on the columns in subset. keep="last" keeps the final occurrence of each email, which is the newest record here. With no subset, rows that differ in source or score are not duplicates at all.
A hint if you get stuck
drop_duplicates takes subset (which columns define a duplicate) and keep ("first" or "last").
This exercise is part of Pro
Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.
You create a free account first, so Pro is attached to it.
Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.