parallax background

What is Data Cleaning?

data management
Step by Step LLM Evaluation
machine learning
Exploring Machine Learning Algorithms


What is Data Cleaning? — Garbage In, Garbage Out
Data Fundamentals

Garbage in, garbage out.

Before the model, before the dashboard, before the decision — someone has to fix the data. Data cleaning is that work: finding everything wrong with a dataset and making it worthy of trust.

01The reality

The unglamorous majority#

Ask a data team what they actually do all day and the honest answer is: clean. The model gets the glory; the cleaning gets the hours.

Missing valuesGaps that stop calculations — or silently bias them.
DuplicatesThe same record counted twice; metrics inflate quietly.
Structural errors“USA”, “us ”, “United States” — one value, three groups.
OutliersErrors to fix, or the rare signals you were hired to find.
76% of data professionals still rely on spreadsheets as their primary cleaning tool — Alteryx, 2025
43% of COOs rank data quality as their top data priority — IBM, 2025
80% of a typical data project’s hours go to finding and fixing data issues (illustrative)
6 core operations cover nearly every cleaning job you will ever meet
The usual suspects
6 recurring enemies Illustrative mix of issue types found when profiling real-world datasets.
Duplicates · 24Missing values · 22Inconsistent formats · 19Invalid values · 14Outliers · 11Stale data · 10

How to read this: no dataset fails in one dramatic way — it fails in six boring ways at once. Duplicates and gaps usually lead the pack.

02The operations

Six moves, in order#

The craft is small: six operations, each with a decision at its heart. Learn the decisions and the tools are interchangeable.

Every cleaning job starts the same way: look. Profiling means computing the shape of your dataset — row counts, data types, null rates, value distributions, suspicious ranges — before changing a single cell. Ten minutes of profiling routinely saves hours of cleaning the wrong thing.

profile.py
import pandas as pd

df = pd.read_csv("orders.csv")

df.info()          # dtypes + non-null counts per column
df.describe()      # min / max / mean — impossible values surface here
df["country"].value_counts()  # "US", "USA", "us ", "United States"…
  1. Null rates per column — a 40%-empty column is a design problem, not a fillna problem.
  2. Impossible ranges — age 250, negative prices, dates in the future.
  3. Cardinality surprises — 47 variants of the same country name.
  4. Format drift — dates stored as text, numbers with currency symbols.

Duplicates arrive from retried API calls, merged systems, and copy-paste exports. They inflate counts, skew averages, and make you doubt which record is authoritative. The fix is a decision: define what makes two rows the same, then keep one — usually the most recent.

dedupe.py
# Same customer, latest record wins
df = (df.sort_values("updated_at")
        .drop_duplicates(subset=["email"], keep="last"))
Gotcha: uniqueness can span several columns.A customer can legitimately appear twice with the same name — dedupe on name + email + account, not name alone, or you will delete real data.

Blanks stop calculations cold — or worse, silently skew them. There are three legitimate moves: drop the row or column, impute a value (median, forward-fill, model-based), or flag the gap and keep it visible. The wrong default is pretending the gap isn’t there.

Drop when

  • Rows are few and random: losing 2% changes nothing.
  • The column is mostly empty: 70% missing is a dead feature.

Impute when

  • Gaps are random: median for skewed numbers, mode for categories.
  • Order matters: forward-fill in time series, never random sampling.
impute.py
df["age_was_missing"] = df["age"].isna()  # keep the evidence
df["age"] = df["age"].fillna(df["age"].median())
Missingness itself is data.A missing “spouse” field often means “no spouse.” Record the flag before you fill — it can be the most predictive column you have.

Structural errors are the tyranny of small differences: capitalization, abbreviations, date formats, units, trailing spaces. Each variant becomes its own group, and every grouped report quietly lies. Pick one canonical form per column and enforce it.

standardize.py
df["country"] = (df["country"].str.strip().str.lower()
    .replace({"usa": "united states", "us": "united states",
              "u.s.a.": "united states"}))
df["order_date"] = pd.to_datetime(df["order_date"], format="mixed")
  1. Dates: 03/04/2026 — March 4th or April 3rd? Pick ISO and document it.
  2. Units: kg vs lb, USD vs EUR — convert, don’t concatenate.
  3. Categories: one canonical spelling per value, kept in a mapping table.
  4. Whitespace: invisible, and the cause of half your failed joins.

A price of −4 is an error. A customer buying 10,000 units is a whale — or fraud. Outlier handling is not deletion; it is investigation. Statistical fences (like the 1.5×IQR rule) flag candidates; domain knowledge decides their fate.

outliers.py
q1, q3 = df["amount"].quantile([0.25, 0.75])
iqr = q3 - q1
fence = (q1 - 1.5 * iqr, q3 + 1.5 * iqr)
suspect = df[~df["amount"].between(*fence)]  # review, don't delete

Probably an error

  • Physically impossible: age 250, humidity 140%.
  • Unit confusion: a sensor that switched from °C to °F.

Probably a signal

  • Whales and fraud: rare, real, and exactly what you’re looking for.
  • Regime change: the week the world changed is not noise.

The job ends not when the data looks clean, but when it fails loudly the next time it isn’t. Validation turns your assumptions into executable tests — frameworks like Great Expectations or pandera run them on every new batch, forever.

validate.py
assert df["email"].notna().all(), "null emails found"
assert df["amount"].ge(0).all(), "negative amount"
assert df["order_date"].max() <= pd.Timestamp.today()
# loud failure now > quiet wrong dashboard for six months
Gotcha: validation belongs in the pipeline, not the notebook.A check you ran once, by hand, in March, protects nobody in August. Automate it where the data flows.
03The tools

Pick your weapon#

The tool matters less than the discipline, but the right tool makes the discipline cheap.

ToolKindBest for
pandas / PolarsCode (Python)Cleaning as a reproducible script — the default for data teams
SQLIn-warehouseDedupe and standardize where the data already lives
OpenRefineFree desktop appClustering near-duplicate text values in messy columns
Great ExpectationsValidation frameworkTurning “I think it’s clean” into automated pipeline tests
Alteryx / Power QueryNo-code platformsAnalysts owning pipelines without writing code
AI-assisted cleaningML-suggested fixesAnomaly detection and suggested transforms at scale — review before applying
AI can suggest; only you can approve.2026 tools infer types, flag anomalies, and propose fixes impressively well — and still merge two different customers with total confidence. Every AI-suggested transform gets human review before it touches a production pipeline.
04The discipline

Cleaning is a discipline, not a phase#

Data does not stay clean. New records bring new errors, so the winners are not the teams that cleaned once — they are the teams that made cleaning cheap to repeat.

1
Profile before you fix.

You cannot repair what you have not measured. Ten minutes of looking beats a day of guessing.

2
Fix at the source when you can.

A validation rule in the entry form beats a thousand corrections downstream.

3
Write cleaning as code, not clicks.

If it cannot be re-run next month on new data, it is not finished.

4
Validate like a skeptic.

The job ends with tests that fail loudly — not with a dataset that looks fine today.

The real deliverable: not a clean dataset — a repeatable way to get one.

05Grounding

Sources#

The survey figures quoted inline come from these reports; the donut chart and the 80% time share are illustrative composites, as marked.

  1. Alteryx (February 2025). “The 2025 State of Data Analysts in the Age of AI.” Survey of 1,400 data, IT and operations analysts across five industries (fieldwork by Coleman Parkes, Nov–Dec 2024): 76% still use spreadsheets as their primary tool for cleaning and preparing data; 45% spend more than six hours a week on data cleansing. alteryx.com — press release
  2. IBM Institute for Business Value (2025), via IBM Think. “The True Cost of Poor Data Quality.” 43% of chief operations officers identify data quality issues as their most significant data priority; over a quarter of organizations estimate losses above USD 5 million a year from poor data quality. ibm.com/think/insights/cost-of-poor-data-quality
  3. Gil Press, Forbes (2016), reporting the CrowdFlower Data Science Survey. “Cleaning Big Data: Most Time-Consuming, Least Enjoyable Data Science Task.” 60% of data scientists’ time goes to cleaning and organizing data, 19% to collecting data sets — and cleaning is the least enjoyed part of the job. forbes.com
  4. Wickham, H. (2014). “Tidy Data.” Journal of Statistical Software, 59(10). The philosophy behind the standardize step: each variable a column, each observation a row — most cleaning is getting to that. doi.org/10.18637/jss.v059.i10
  5. OpenRefine. The free, open-source desktop tool for clustering near-duplicate values and reconciling messy columns, as listed in the tools table. openrefine.org
No model outperforms its data.
Part of the Data Fundamentals series · Updated 6 August 2026. The issue-mix chart and time share are illustrative; survey figures are cited inline.
Ali Reza Rashidi
Ali Reza Rashidi
Ali Reza Rashidi, a Senior Data Scientist-Gen Al | Al Architect | MLOps with over ten years of experience, He is the author of three books that delve into the world of data and management.

Comments are closed.

error: Content is protected!