Handling Duplicate Data
Finding duplicate records is a key part of data cleansing. It's not just about deleting rows with the same ID; duplicates can be subtle and require careful handling to avoid corrupting your dataset. The footgun is assuming all duplicates are safe to delete.
Why it exists
Datasets often contain duplicate entries due to user error, system glitches during data entry, or issues when merging data from multiple sources. These duplicates can inflate counts, skew statistical analyses, and cause models to give incorrect weight to certain patterns. Handling duplicates is a fundamental step in data cleansing to ensure data integrity.
The mental model
Think of handling duplicates like de-duping your contact list. You might have two entries for "John Smith"—one with a work email and one with a personal phone number. Simply deleting one would lose information. The goal is to merge them into a single, complete, and accurate record. This is the core challenge of handling duplicates: not just deleting, but intelligently reconciling.
How it works
The process starts with defining what constitutes a duplicate. It could be an identical match across all columns, or a match on a specific set of key identifiers (like name and date of birth). Once potential duplicates are identified, you must decide on a strategy. The options, drawn from the general principles of data cleansing, are: modifying one record to incorporate information from another, merging multiple records into a single "golden record," or deleting the truly redundant entries. This can be done with scripts in batch processing or with interactive data wrangling tools.
When to use it
Always check for duplicates before performing any kind of aggregation, analysis, or model training. It's a critical step when combining datasets from different sources. For example, when merging customer lists from two acquired companies, you must de-duplicate to get an accurate total customer count.
When not to use it
Don't remove duplicates from raw, transactional logs where repeated events are meaningful. For instance, multiple identical purchase records for a user might represent distinct, valid transactions, not an error. Blindly deleting these "duplicates" would corrupt the sales data. The key is to understand the data's origin and purpose before deciding if a repeated record is an error.
One canonical example
In a user database, you might find two records for "Jane Doe," one with email jane.doe@example.com and a mailing address, and another with j.doe@example.com and a phone number. A script could identify these as probable duplicates based on the similar name and email structure. Instead of deleting one, a cleansing process would merge them, creating a single record for "Jane Doe" that contains both emails, the address, and the phone number, thus creating a more complete and accurate record.
Interview question
According to the mental model for handling duplicates, what is the primary goal?
- a.To flag potential errors for manual review without altering the original data.
- b.To identify and delete all instances where data appears more than once.
- c.To consolidate fragmented information into a single, complete, and accurate record.Correct
- d.To reduce the overall size of the dataset by eliminating redundant entries.
Why? this is the answer
The card states the mental model's goal is to "merge them into a single, complete, and accurate record," emphasizing intelligent reconciliation over simple deletion. Option B is a common misconception and explicitly warned against as a "footgun" because it can lead to loss of valuable information or valid transactional data.
Just read this? Test yourself on what you have been reading.
Read the original → en.wikipedia.org
- #data cleaning
- #data integrity
- #etl
- #data science
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles