Wrangling Is Not Cosmetic Cleanup
Learning objective: define dataset grain; distinguish formatting from semantic quality; establish raw/staging/clean zones.
Many people think of data wrangling as tidying column names or fixing colors. What actually decides whether an analysis can be trusted is two more basic questions: what is this dataset's grain, and can every transformation be re-run to get the same result?
Cosmetic cleanup only
Column names look consistent, numbers get thousands separators, blanks get filled so the table looks complete, but nobody has confirmed what each row actually represents.
Checking semantic quality too
- Grain
- Confirm what one row represents first: one company per year, or one site per month?
- Zones
- Keep the raw file untouched, do transformations in staging, and only move validated results into clean.
- Reproducibility
- Every transformation is code or a logged step; running it again should give the same result.
| Zone | Content | Rule |
|---|---|---|
| Raw | The file exactly as it arrived, never modified | Always keep one copy as the starting point for traceability |
| Staging | Intermediate results of type conversion, cleaning and reshaping | Reproducible; never treated as the final conclusion |
| Clean | Analysis-ready data that has passed validation rules | Only this zone is used directly for metric calculation |
- A column name contains "total" or "avg" but nobody states which dimension it was aggregated across
- The same company_id has a different number of rows in the raw file each time, with no explanation
- The row count changes after merging two sources, but nobody checks it against the expected count
import pandas as pd
# raw: never modify it; look at it first
raw = pd.read_csv("DS102_Company_Year_Practice.csv")
raw.shape
raw.head()An analyst sums a company's four quarterly electricity readings into one annual number, then compares it against another "annual" dataset. Both tables look like "one number per year," but one is a sum of quarters and the other is a direct annual measurement; the calculation methods differ, so comparing them directly produces a wrong conclusion, and the code never raises an error.
Warning
Info
Each row of a dataset represents "one company in one year." Which approach best protects that grain?