What Is Data Cleaning? Find and Fix Problems Without Losing Meaning
Data cleaning means finding and correcting errors or inconsistencies that interfere with analysis while preserving what the records mean. To clean data safely, define what each row represents and what counts as a valid value, preserve the source, record each transformation, and validate the result. A blank or duplicate candidate should not be filled or deleted automatically; doing so can change valid facts.
What Is Data Cleaning? Find and Fix Problems Without Losing Meaning
Data cleaning means finding and correcting errors or inconsistencies that interfere with analysis while preserving what the records mean. To clean data safely, define what each row represents and what counts as a valid value, preserve the source, record each transformation, and validate the result. A blank or duplicate candidate should not be filled or deleted automatically; doing so can change valid facts.
What should be corrected, and what should remain?
Common quality problems include typing mistakes, inconsistent date or unit formats, missing values, incorrect data types, repeated copies of the same event, and values that violate a rule. When combining sources, the same item may be represented differently or sources may disagree. Cleaning finds and resolves such problems, often alongside work that reshapes tables or combines sources. The boundary between these tasks varies by tool and organization. Rahm and Do describe cleaning as addressing errors and inconsistencies in both single sources and integrated data.
But an unfamiliar or extreme value is not automatically wrong. A negative sales amount could be a refund; a missing birth date could mean it was not collected or the person declined to provide it. Do not replace values with what merely looks plausible. Use criteria confirmed by a data dictionary, business rule, or source record. If there is no evidence, preserve the value as missing or flag it for review instead of guessing.
Define what the table means before cleaning it
First establish the dataset’s scope and unit of observation. Whether one row represents an order, a customer, or an order line changes how duplicates and totals should be handled. Check the column that identifies each observation, such as a primary key, along with units, currency, date conventions, allowed values, and rules for joining other tables.
A tidy table usually puts one variable in each column, one observation in each row, and each type of observational unit in its own table. This structure supports analysis and transformation, but it does not guarantee that values are correct. Wickham’s explanation of tidy data describes this structure as one part of preparing data.
A safe sequence that preserves the source
**Preserve the source.** Do not overwrite the received file or source table. Make a working copy and record the source, extraction time, row count, and transformations so you can trace later changes.
**Inspect candidate problems.** Check column names and types, missing values, unique values, duplicate candidates, plausible ranges, and logical relationships between columns. For example, check whether an end date precedes a start date or an amount violates a stated business rule.
**Classify the candidates.** Separate formatting differences, errors confirmed against the source, ambiguous values, and unusual but possible values. Do not automatically fix a candidate unless you can explain the rule.
**Apply and record transformations.** Use reproducible rules such as trimming whitespace, mapping standard codes, or converting units. Keep the original column and add a cleaned column when the original value matters. Distinguish kinds and reasons for missingness; do not replace every blank with a mean or most common value.
**Compare the result with the source.** Compare row counts, key uniqueness, types and units, missing counts, and important totals or rates before and after. Check a sample against source records and make sure joins did not unexpectedly multiply or drop rows.
**Save the cleaned data with its rules.** Keep the analysis-ready output, transformation steps, reasons for changes, and unresolved items together. Cleaning does not eliminate uncertainty; it makes clear which values are reliable and which still need review.
Distinguishing duplicates and missing values in an order table
The table below is a hypothetical order dataset for explaining the process. In this example, the source system guarantees that order_id identifies one order and that a repeated ID does not represent a separate event.
| Source row | order_id | Date | Region | Amount |
|---|---|---|---|---|
| 1 | ORD-31 | 2026-05-02 | Seoul | 12,000 KRW |
| 2 | ORD-31 | 2026-05-02 | Seoul | 12,000 KRW |
| 3 | ORD-32 | 2026-05-02 | Busan | 5,000 KRW |
| 4 | ORD-33 | 2026/05/03 | (blank) | 8,000 KRW |
The first two rows differ only in whitespace around the region. After trimming and standardizing the region code, if both rows still have the same order ID and values, check the source rule and extraction history to determine whether the event was captured twice. If that assumption is confirmed, exclude one copy from the analysis dataset and record the reason, while retaining the source. Row 3 has a different order ID, so it is not the same order merely because its date and amount are similar.
For row 4, normalize the date only after confirming what slash notation means in the source. Leave the region missing if there is no source to verify it. Inferring it from nearby orders could turn a guess into an apparent fact.
Here is an illustrative pandas example that flags missing values and duplicate-key candidates. First confirm that order_id is a unique key under the business rules. The code finds rows to review; it does not delete them.
missing_by_column = df.isna().sum()
duplicate_order_rows = df.loc[
df["order_id"].notna()
& df.duplicated(subset=["order_id"], keep=False)
]isna() checks for missing values, while duplicated(..., keep=False) selects all rows marked as duplicates for the chosen columns. Because pandas can represent missing values differently depending on the data type, use missing-value checks instead of ordinary equality comparisons. See the pandas missing-data guide and the DataFrame.duplicated reference. This code is an illustration; it is not a claim that the example was executed or tested.
What to verify after cleaning
Before saving the output, compare it with the source definitions. For an order table, confirm that order_id is unique if the rule requires it, that total amounts still reconcile with source aggregates within an explainable range, and that the date coverage includes the intended period. Record why row counts or key statistics changed. Also record the rule and evidence used to fill missing values or combine duplicates.
“Clean” does not mean that every unusual value has disappeared. It means the defined rules were applied, important changes can be explained, and analysts can see what remains uncertain. Change no more than the analysis requires, and preserve the source, cleaned output, and procedure so the result can be reproduced and reviewed.
Sources
[Erhard Rahm and Hong Hai Do, “Data Cleaning: Problems and Current Approaches”](https://cs.brown.edu/courses/csci2270/archives/2016/papers/Rahm2000DataCleaningProblemsand.pdf)
[Hadley Wickham, “Tidy Data,” Journal of Statistical Software](https://www.jstatsoft.org/article/view/v059i10/)
[pandas 3.1.1 documentation: Working with missing data](https://pandas.pydata.org/docs/user_guide/missing_data.html)
[pandas 3.1.1 API reference: `DataFrame.duplicated`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.duplicated.html)