Data Cleaning &
Preprocessing
Learn to transform messy, real-world data into clean, analysis-ready datasets: handling missing values, removing duplicates, and standardizing formats.
Why Clean Data Matters
Every business decision powered by data is only as good as the data itself. Studies show that data scientists spend roughly 80% of their time cleaning and preparing data, and only 20% on actual analysis.
Data cleaning is the foundational skill that separates meaningful insights from misleading conclusions.
Key Definitions
The Data Quality Pipeline
Five Pillars of Data Quality
Types of Dirty Data
Cleaning vs Preprocessing
| Aspect | Data Cleaning | Data Preprocessing |
|---|---|---|
| Goal | Fix errors and fill gaps | Transform data for models |
| Focus | Quality and correctness | Format and structure |
| Examples | Remove duplicates, fix typos | Normalize, encode categories |
| When | First (before preprocessing) | After cleaning is complete |
| Analogy | Washing vegetables | Chopping and seasoning |
Handling Missing Values
The Cleaning Checklist
Example 1: Spotting Problems
You receive this customer dataset. Can you spot the issues?
Example 2: Fixing the Data
Example 3: Normalization
After cleaning, we often need to normalize numeric columns so they share a common scale. This prevents large-valued features from dominating analysis.
Example: If ages range from 28 to 41, then for age = 34:
Z-Score Standardization
Example: If the "Spent" column has \(\mu = 141.83\) and \(\sigma = 51.26\), then for a customer who spent \(\$200.50\):
Encoding Categorical Data
Most analytical tools require numeric input. Categorical variables like "City" or "Color" must be encoded into numbers.
Outlier Detection: IQR Method
Common Mistakes
Summary of Techniques
| Technique | When to Use | Watch Out For |
|---|---|---|
| Delete rows/cols | < 5% missing | Data loss |
| Mean/median imputation | Numeric columns | Reduces variance |
| Mode imputation | Categorical columns | Over-represents mode |
| Min-Max normalization | Bounded features | Sensitive to outliers |
| Z-Score standardization | Unbounded features | Assumes approximately normal dist. |
| One-hot encoding | Nominal categories | High cardinality = many cols |
Question 1 of 5
A dataset has 10,000 rows. The "Phone Number" column has 8,200 missing values. What is the best approach?
Question 2 of 5
Which formula correctly performs Min-Max normalization?
Question 3 of 5
A "Color" column contains values: Red, Blue, Green, Yellow. You need to prepare it for a machine learning model. Which encoding avoids implying a false ordering?
Question 4 of 5
A dataset records customer ages. The values for \(Q_1 = 25\), \(Q_3 = 45\), so \(\text{IQR} = 20\). Using the IQR rule, which age would be flagged as an outlier?
Question 5 of 5
You computed a Z-score of \(z = -2.3\) for a data point. What does this mean?