Start studying
Module 7 · Data Cleaning Module contents
Module 7  ·  Card 3 / 13beginner

Deduplication

Deduplication removes repeated records so that each real thing appears in the data once.

Exact duplicates match in every column and often come from loading the same file twice.

Near duplicates differ slightly, such as Jon Smith and John Smith listed at the same address.

In pandas, duplicated flags repeated rows and drop_duplicates removes them, optionally comparing only chosen columns.

Duplicates inflate counts and totals, so a customer listed twice is counted as 2 customers.

Learn in depth ↓
Module 07 · Data Cleaning · 13 concepts
In depth  /  15 lines

Deduplication, in more detail

Duplicates appear whenever the same record enters a dataset by more than one route.

Files loaded twice, forms submitted twice and systems merged together are the usual sources.

Removing them matters because almost every count, sum and average assumes one row per real thing.

The first step is deciding what makes 2 rows the same, which is called the key.

For orders the key might be the order number, while for people it might be name, date of birth and postcode together.

Checking only the key columns catches rows that repeat the same order with a slightly different load time.

Once duplicates are found, one copy must be kept, often the first, the latest or the most complete.

In pandas the keep option of drop_duplicates chooses the first copy, the last copy, or none at all.

Near duplicates need fuzzy matching, which scores how similar 2 strings are rather than testing for an exact match.

Fuzzy matching makes 2 kinds of mistake: merging different people who look alike, and missing the same person written oddly.

Comparing every row with every other grows slow very fast, so candidates are usually grouped first, for example by postcode.

Deleting the wrong copy loses information, such as a newer phone number held only in the second record.

Merging the copies field by field, keeping the best value of each, avoids that loss at the cost of more work.

In practice the number of duplicates removed is logged on every run, so a sudden jump gets noticed.

The usual mistake is deduplicating on every column, which misses copies that differ only in a load time.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
A report counts 10,400 customers, but the customer system holds 10,000. The import log shows one daily file was loaded twice. What is the likely fix?
Data Cleaning

13 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close