Skip to content
Getting Digital

Data Wrangling

Also: data cleaning, data munging, data preparation

Data wrangling is the work of repairing and reshaping real records, and of deciding what their gaps and inconsistencies mean, until a table can be trusted with the question being asked of it.

Assessment. Every cleaning decision belongs in code that can be re-run, never in a spreadsheet edited by hand. A result you cannot reproduce from the raw extract is not a finding, it is a recollection, and it will not survive the first person who disagrees with it.

Nothing arrives ready. The records were produced by a system built for a purpose that was not analysis, and they reach you carrying every historical decision anyone ever made about them: the migration that renamed half the product catalogue, the free-text field a support team repurposed as a status flag, the test accounts nobody removed. Wrangling is the process of discovering all of that and deciding how to respond, and the deciding is the half that gets underestimated. Replacing a blank with a zero, dropping rows that are missing a value, folding two spellings into one category: each is a judgement that moves the eventual answer, made quickly, early and usually without being written down anywhere. The stage deserves more respect than it gets, because most of the error in a final number is either introduced here or prevented here, usually by somebody in a hurry.

  • Row counts either side of every join. A join that returns more rows than it started with has duplicated something; one that returns fewer has silently dropped something. Both are routine and neither raises an error.
  • What a blank means. Not measured, measured as zero, declined and not applicable are four situations arriving as the same empty cell. Filling them all with zero is a decision about all four at once.
  • Duplicates that are not duplicates. One person with two email addresses, one order written twice by a retried webhook, and two different customers sharing a name are three problems wanting three fixes.
  • Dates and time zones. A timestamp with no zone attached is an open question, and daylight saving converts it into a wrong answer twice a year.
  • Categories that drift. DE, Germany, germany and a version with a trailing space are one country until you group by the column.
  • Units, currencies and definitions. A revenue column can be gross or net, booked or recognised, converted at the rate on the day or at today's rate, and nothing in its name will tell you which.

Do it in code, not by hand

The practical rule: the raw extract is read-only and everything done to it is a script. Open a file in a spreadsheet, sort a column, save, and the provenance has gone: nobody can establish afterwards which cells changed or why, including you. Written as code, the sequence survives, which lets a reviewer disagree with one step instead of distrusting the whole table, and turns next quarter's version into a few minutes instead of a second excavation. On tools, pandas is the sensible default, because it is what the notebooks already sitting in most teams are written in. Polars is the better engine once a file is large enough to make a laptop labour, and its expression syntax makes it harder to lose track of what a long chain of operations does. Whatever can be done in SQL should be: filtering and joining millions of rows is what a warehouse was built for, and hauling them into memory to do the same thing more slowly is the signature habit of somebody who learned pandas first. At some point this stops being wrangling at all: once the same repairs run every week on data arriving to a schedule, the work has become data engineering and belongs in dbt, where it can be tested and versioned.

In practice

One instance, because it catches nearly everybody once. You join an orders table to an order lines table in order to attach product details, then count orders, and the count comes back far higher than before. Nothing failed and nothing warned you. The join has multiplied each order by its number of lines, so you are now counting lines while calling them orders, and any sum of an order-level value such as the shipping fee has been inflated by exactly the same factor. The discipline that prevents it is checking the row count immediately after every join, and knowing in advance which side was supposed to be unique. The repairs are ordinary: aggregate the lines first and join the summary, or count distinct order identifiers. The check matters more than the repair, because the version of this mistake that hurts is the version nobody noticed.

Often confused with

Data Engineering
Identical operations, different lifespan and different accountability. Wrangling is repair performed once for one question; engineering is the scheduled version that has to keep working when the source changes shape.
Data Analysis
Wrangling settles what the table says, analysis settles what it means. The same person usually does both in the same afternoon, which is precisely why the cleaning judgements so rarely make it into the write-up.

Key takeaways

  • →The judgements made while cleaning, about blanks, duplicates and categories, shape the conclusion as much as any later technique does.
  • →Check row counts around joins and interrogate what an empty cell means before trusting anything downstream of either.
  • →Keep the raw extract untouched and the repairs in code; once the repairs run on a schedule, move them into the engineering layer.

Related concepts

  • Wrangling is the first stage of the data-analysis loop.

  • Data engineering is the industrial-scale form of wrangling.

  • Wrangling handles the defects that passed the checks, one analysis at a time.

Courses that teach this

Where this concept sits in the field

Certifications that test this

Vendor exams whose syllabus covers this concept: facts, cost and a preparation path on each page.

More courses from these categories

Courses from the categories where this concept is taught. Details, price and the provider link are on each course page.

FAQ

How do I know when it is clean enough?
When you can state what you repaired and what you deliberately left alone, and when the defects still in the table could not move the answer. The test is cheap: take your most doubtful cleaning decision, assume the opposite, and re-run. If the conclusion holds either way, you are finished. If it flips, that decision is no longer housekeeping, it is the finding, and it belongs in the report.
Can an AI assistant do this for me?
It is useful on the mechanical half: parsing awkward formats, spotting inconsistent spellings, drafting the transformation you were about to write anyway. It is unreliable on the half that decides the answer, because knowing whether an empty cell in this column means zero or means unrecorded is knowledge about the business, not about the data, and no amount of staring at the file reveals it. Let it write the code. Do not let it choose the assumptions.

Sources

The primary text this definition rests on. Read it before relying on this one.

Last reviewed 26 September 2026 · Getting Digital