Data Cleaning and Quality Checks
Finding and fixing missing values, duplicates, inconsistent categories, bad types and outliers, and documenting every decision.
Intermediate · about 8 hours · difficulty 3/5
Learn first: pandas for Data Analysis, Descriptive Statistics
Real data is messy. Cleaning is not glamorous, but every insight downstream depends on it. The goal is not perfect data; it is data whose remaining flaws you understand and have disclosed.
A cleaning checklist
- Types: numbers stored as text, dates in mixed formats, IDs losing leading zeros.
- Missing values: count them per column. Decide per case: drop, fill with a sensible default, impute, or keep and flag. Ask why they are missing; missing-not-at-random changes conclusions.
- Duplicates: exact duplicates and near duplicates (same customer, different capitalisation). Define what makes a row unique first.
- Inconsistent categories: "USA", "U.S.", "United States". Normalise with mapping tables,
str.strip().str.lower(), and reviewvalue_counts. - Outliers and impossible values: negative ages, orders dated in 2099, prices of 0. Distinguish errors (fix or remove) from genuine extremes (keep, maybe analyse separately).
- Test and internal records: staff accounts, QA orders.
Validate as you go
- Row counts before and after each step.
- Totals reconciled against a trusted source (finance report, source system).
- Assertions in code:
assert df["order_id"].is_unique.
Document decisions
Keep a cleaning log: what you changed, why, and how many rows were affected. It protects you when someone asks why your number differs from theirs.
Pitfall: filling missing values with zero by default, which silently changes averages. Move on when you can hand over a cleaned dataset with a short log explaining every transformation.
Key concepts
- Type fixing and parsing dates
- Missing value strategies
- Deduplication
- Standardising categories and text
- Outliers vs errors
- Reconciliation and assertions
- Cleaning logs
- Fuzzy matching
Mini project
Clean the NYC Airbnb or a messy Kaggle dataset (e.g. 'Data Science Job Salaries' or a scraped listings file): fix types, standardise categories, handle missing values, and publish a cleaning log alongside the final CSV.
Check yourself
Why should you ask why values are missing before deciding how to fill them?
Free resources
- Kaggle Data Cleaning course (Kaggle)
- pandas: working with missing data (pandas)