Data cleaning

Turning a messy download into an analysis-ready dataset you can trust.

A cleaning report recording the rule applied at each step, not only how many rows it removed. the count says how many; only the rule says whystepremovedthe ruleduplicatesinvalid geometrymissing CRS31244 repaired1,205drop_duplicates(subset=["id"])make_valid()refused — never guessedIn six months the counts mean nothing and the rules still reproduce the dataset

Cleaning is where an analysis acquires its assumptions, which is why it deserves to be written down rather than done interactively. Every step is a rule applied to a set of rows, and the rule is the part that matters: "removed 312" tells a reader how many, and only the rule tells them why.

The work itself is unglamorous and specific: coordinate columns stored as text, decimal commas, swapped latitude and longitude, duplicate geometries that differ in the eighth decimal place, categories spelled four ways, missing values encoded as −9999 and as the empty string in the same file. Almost none of it raises an error; it produces a dataset that looks finished.

The pages below cover what to check before trusting a file, the operations that fix each defect, and a repeatable report that makes the whole thing reproducible six months later.

Learning paths run through this topic too — see the end of this page.

🧭 Start with the concepts

The ideas the how-to guides below assume you already have.

Show every concept in this topic

⚙️ Then do the task

Step-by-step walkthroughs with code you can copy and adapt.

Show every how-to guide in this topic

🔧 When it breaks

The errors this topic produces, with the cause explained rather than just the command.

Show every fix in this topic

Related topics

Subjects that keep coming up alongside this one, most overlap first.

Keep browsing

Data cleaning sits in Analysis. Every topic on the site is listed on the topics index.