Clean a Messy Dataset With AI
Take a genuinely messy spreadsheet and build a documented cleaning process. The rule throughout: AI proposes the rules, you apply them, and every change is reversible and logged.
Why this one
Pasting a spreadsheet into a chatbot and asking it to clean the data produces a new spreadsheet with silent, unexplained changes. That is unusable for anything that matters. The alternative is to use the model for judgement — what counts as a duplicate here? — and keep the execution somewhere you can audit.
Steps
Profile before you touch anything
Paste twenty representative rows, including the ugly ones, and ask what is wrong. You want an inventory: inconsistent formats, missing values, likely duplicates, impossible values, mixed units. Include the ugly rows deliberately — a clean sample produces a clean report and a false sense of security.
Turn problems into explicit rules
For each problem, get a rule precise enough to apply mechanically, and force the ambiguous cases into the open.
PromptHere is a data quality report for a dataset. For each issue, write a cleaning rule precise enough that two people applying it independently would get the same result. State explicitly what to do with edge cases and what should be flagged for a human rather than auto-corrected. ISSUES: [paste] SAMPLE ROWS: [paste]
Decide what must never be auto-corrected
Some fields carry meaning that a plausible guess destroys — identifiers, financial amounts, anything legally significant. Write these down as a do-not-touch list before you start. A model asked to clean data will happily normalise an account number.
Apply the rules where you can see them
Use formulas, find-and-replace, or a short script — anything where the transformation is visible and undoable. Keep the original file untouched. If you do use AI to generate a script, read it before running it against real data.
Verify by sampling, not by feel
Pull twenty random rows from the cleaned file and check them against the original by hand. Count how many are wrong. That number, not a general impression, is your error rate, and it tells you whether the cleaned data is usable.
You should end up with
A cleaned dataset, a written rule list, and a measured error rate.
Done when
- Every transformation is documented and reversible
- Sensitive fields were flagged rather than auto-corrected
- You sampled the output and can state the error rate
If you want to go further
- Turn the rule list into a reusable script for next time
- Add a validation step that rejects rows failing the rules rather than fixing them