Back to prompts
Code18.10.2026
Write a Python Script That Cleans a Messy CSV Export Before Year End Reporting
#python#csv#data cleaning#pandas#year end reporting#automation#viral
You are a careful data engineer who writes small, readable Python scripts that non experts can run safely. I have a messy CSV export that I need to clean before year end reporting. Write a script based only on the columns and problems I describe. Do not invent columns, business rules, or data. If something is missing, mark it [NEEDS INPUT]. Where the export comes from (CRM, store platform, accounting tool, spreadsheet): [SOURCE] Column names exactly as they appear in the header row, plus a few sample rows with sensitive values replaced: [COLUMNS AND SAMPLE] Problems I already see (duplicate rows, mixed date formats, currency symbols in numbers, extra spaces, blank rows, inconsistent country or status names): [PROBLEMS] What the clean file needs to look like for my report (columns to keep, date format, number format, sort order): [OUTPUT SPEC] My Python setup (version, whether pandas is installed, Windows or Mac): [SETUP] File size, roughly how many rows: [SIZE] Requirements: 1. Restate the cleaning rules you will apply, one per line, based on [PROBLEMS] and [OUTPUT SPEC], so I can confirm them before running anything. 2. Write a single script that reads the input path and writes to a new output file. Never overwrite the original file. 3. Handle each problem in [PROBLEMS] with a clearly commented step: trim whitespace, normalize dates to the format in [OUTPUT SPEC], strip currency symbols and thousands separators before converting to numbers, standardize category values with a mapping I can edit, and drop fully blank rows. 4. For duplicates, explain which columns define a duplicate and keep a separate file of removed rows so nothing disappears silently. 5. Write rows that fail validation (unparseable dates, non numeric amounts, missing required fields) to an errors file with a reason column instead of guessing a fix. 6. Print a short summary at the end: rows read, rows written, duplicates removed, rows sent to errors, and totals of key amount columns before and after cleaning. 7. If [SIZE] is large, read the file in chunks and explain why. If pandas is not available in [SETUP], use the standard csv module instead. 8. Give step by step run instructions for [SETUP] in plain language, and a quick way to spot check the output against the original in a spreadsheet. Deliverables: 1. Cleaning rules list to confirm 2. Complete commented Python script 3. Duplicate and error file explanation 4. Run instructions and spot check steps 5. A list of [NEEDS INPUT] questions
How to use this prompt
- 1Copy the prompt using the button above.
- 2Open your AI tool (ChatGPT, Claude, Midjourney, etc.)
- 3Paste and customize any variables in the prompt.
- 4Generate your result.
Tip
Fill every placeholder before you run the prompt. Keep one clear goal per run, then refine with a follow-up if needed.
When to use this prompt
- •Good for first drafts in Code
- •Keep variables filled so the model has enough context
- •Review AI output before sending or publishing