Write a Python Script That Cleans a Messy Data File Safely

AU Business & Compliance Claude intermediate

Paste a sample of your messy CSV or export and get a runnable cleaning script — stated assumptions, per-rule functions, a rejects file and a printed report.

When to use it: When an export from your POS, bank or booking system is full of blank rows, mixed date formats and stray columns, and Excel surgery is eating your evenings.
You are a data engineer writing a small, safe Python cleaning script for a non-engineer. Your scripts never modify the source file and never drop data silently.

<context>
Where the file comes from and how often: [FILE — e.g. weekly bookings export from our scheduling app, CSV]
The problems I can see: [PROBLEMS — e.g. dates in two formats, phone numbers sometimes missing the leading 0, duplicate rows, a merged header line]
The output I need: [TARGET — e.g. one clean CSV: date (YYYY-MM-DD), name, phone, service, price as a number]
File size: [SIZE — e.g. about 2,000 rows]
My setup: [ENV — e.g. Python 3.12, happy to pip install pandas / standard library only]
</context>

<sample>
[PASTE THE HEADER ROW AND 10-15 REAL ROWS, with anything sensitive swapped for fake values in the same format]
</sample>

Before writing code, read the sample and list your inferred schema and every assumption you're making (which date format wins, what counts as a duplicate, how to treat blank prices). Number the assumptions — if any would change the output meaningfully and the sample can't settle it, ask me those questions first and stop.

Then deliver one runnable script that:
1. Reads the source and writes to a NEW timestamped output file — the original is never touched.
2. Implements each cleaning rule as its own small named function with a one-line comment, so I can disable a rule by commenting out one line.
3. Sends rows it cannot confidently fix to a separate rejects file with a reason column — never silently dropped, never silently guessed.
4. Prints a plain-English report at the end: rows read, rows cleaned, rows rejected by reason, duplicates removed.
5. Handles the problems I listed plus their obvious siblings visible in the sample (stray whitespace, inconsistent capitalisation) — nothing speculative beyond that.
6. Ends with run instructions for my exact setup, including the pip line if needed, and the two-minute verification: open the rejects file first, then spot-check five cleaned rows against the source.

Rules: field names and formats come only from my sample and target — anything else is [NEEDED: …]. Keep it one file, no configuration, comments in plain English.

Copy the block above straight into Claude — anything in [BRACKETS] is yours to fill in.

Want it tuned to your business? Bring it to the free weekly call and we'll adapt it live.

Join the free call

More au business & compliance prompts

Plain-English Contract Summariser

Understand what you're signing before you sign it — and know what to ask a professional

Set Up Redirects and Caching on an Apache Site

Get a ready-to-paste .htaccess block with redirects, HTTPS forcing and caching, plus install, test and undo steps.

Script a Hard Conversation Before You Have It

Turn a dreaded workplace conversation into a short, direct script with openers, key lines and responses to likely reactions.