Deduplication, Outliers, and Data Type Validation
Rounding out the cleaning toolkit: finding duplicate records, deciding what to do with extreme values, and enforcing the types and rules your data is supposed to follow.
Finding and Removing Duplicates
Duplicate records inflate counts, distort averages, and double-count revenue or users. They creep in through repeated form submissions, failed retries in a data pipeline, or merging two exports that overlap. An exact duplicate — every column identical across two rows — is easy to catch and safe to drop. A fuzzy duplicate is harder: the same customer entered twice with a typo in the name, a different phone format, or a slightly different address. Catching these usually means normalizing text first (trimming whitespace, lowercasing, stripping punctuation) and then matching on a combination of fields rather than expecting an exact string match.
Before deduplicating, decide what "the same record" means for your data. Two orders with the same customer ID and timestamp are almost certainly a duplicate. Two orders with the same customer ID an hour apart are probably two separate, legitimate purchases. Define your matching key deliberately, and keep a count of how many rows you removed — a dedup step that silently drops 40% of your data is usually a sign the matching key is too loose.
Detecting Outliers
An outlier is a value that sits far outside the typical range for its column. Two common statistical methods for flagging them are the z-score method, which flags any value more than roughly three standard deviations from the mean, and the IQR (interquartile range) method, which flags any value more than 1.5 times the IQR below the first quartile or above the third quartile. IQR is generally more robust than z-score for skewed data, since it doesn't rely on the mean and standard deviation, which extreme values themselves distort.
Statistical thresholds are a starting point, not a verdict. A $50,000 transaction might be a statistical outlier in a dataset of retail purchases and also a perfectly real wholesale order. Domain knowledge decides whether a flagged value is an error or a legitimate extreme case.
Deciding What to Do With an Outlier
There are three honest options, and "delete it" is only sometimes the right one. If the value is clearly an error — a birth year of 1890 for a customer who signed up last week, a negative quantity ordered — correct it if you can determine the true value, or treat it as missing data if you can't. If the value is real but you want to prevent it from dominating a summary statistic, consider winsorizing (capping extreme values at a percentile boundary) rather than deleting the row outright, which preserves the row for other columns. If the value is real and meaningful to the question you're asking, keep it and make sure your summary statistics (median over mean, for instance) aren't misleadingly distorted by it. What you should never do is delete inconvenient real values just because they complicate the story you expected to tell.
Enforcing Data Types and Validation Rules
A column that's supposed to hold dates will happily accept "N/A" as text if nothing stops it, and that one row can break every date calculation downstream. Enforce expected types early: numeric columns should reject non-numeric entries (or convert and flag them), date columns should parse into an actual date type rather than staying as free text, and categorical columns should be checked against a known list of valid values so a typo like "Califronia" doesn't silently become its own category.
Validation rules go a step further than types: an age should fall between 0 and roughly 120, a percentage should fall between 0 and 100, an end date shouldn't precede a start date. Building a short list of these sanity checks and running them after every data refresh catches problems before they reach a dashboard, rather than after a stakeholder notices the numbers look wrong.
Practical Review Checklist
Before moving on, confirm that you can:
- Define what counts as "the same record" before deduplicating
- Distinguish exact duplicates from fuzzy duplicates and know how to catch each
- Explain the difference between the z-score and IQR methods for flagging outliers
- Choose between correcting, capping, keeping, or treating an outlier as missing
- Write at least three validation rules appropriate to a dataset you work with regularly
Conclusion
Deduplication, outlier handling, and type validation share a theme: each requires a decision, not just a mechanical step. Applied thoughtfully, they turn a dataset you can't fully trust into one you can defend.