thinkhard.SI

Prompt repository Data & spreadsheets

Write a Python script that cleans a CSV export you get every week

You clean the same export by hand every week and want a Python script that does it the same way each time and reports what it changed.

Registry no.
DAT-036
Collection
Data & spreadsheets
Laid out for
Any chat model
Score
10 out of 10
Blanks to fill
7
Added

Data & spreadsheetsAny chat

The prompt

Score 10 of 10, Excellent

Use it when You clean the same export by hand every week and want a Python script that does it the same way each time and reports what it changed.

  • {{run_frequency}}
  • {{sample_rows}}
  • {{manual_steps}}
  • {{output_spec}}
  • {{setup}}
  • {{file_locations}}
  • {{max_lines}}
Full prompt and why it works
Prompt
Write a Python script that cleans the CSV export described below the same way every time, for me to run {{run_frequency}} on my own computer, so I stop fixing it by hand and get the same result each run.

The first 20 to 30 rows of the export, including the header and some messy rows:
"""
{{sample_rows}}
"""

The cleaning steps I do by hand now, in order:
"""
{{manual_steps}}
"""

What the cleaned file must look like (columns, order, formats, file name): {{output_spec}}
My setup (Python version, whether I can install packages such as pandas, operating system): {{setup}}
Where the input file is and where the output should go: {{file_locations}}

Requirements:
1. One script file, with a short comment above each step that matches one of my manual steps.
2. The input and output paths set at the top of the file, so I can change them without reading the code.
3. It never overwrites the original export.
4. It prints a short summary at the end: rows read, rows written, rows removed and why, and values changed per column.
5. It stops with a clear message, not a stack trace, if an expected column is missing or renamed.
6. After the script, a short section on how to run it and how to compare the first output with a file I cleaned by hand.

Keep it under {{max_lines}} lines, using only the standard library plus packages my setup allows. Prefer plain, readable code over clever one-liners, because the next person to fix it may not be a programmer.

For example, the end summary might print: "Rows read: 1,204. Removed: 12 blank rows, 3 duplicates by Order ID. Dates changed to YYYY-MM-DD in 2 columns." This example shows the form only.

Do not add cleaning steps I did not list, such as dropping columns or fixing spellings, unless the output spec needs one, and then say so in a comment. If a step in my list is ambiguous, for example "remove duplicates" without saying which columns define a duplicate, list your questions first, write the script for the steps that are clear, and leave the unclear step as a commented placeholder.

Variables

{{run_frequency}}
How often you will run it, for example "every Monday".
{{sample_rows}}
The header and 20 to 30 rows of the export, including the problem rows. Mask any personal data.
{{manual_steps}}
What you do by hand now, step by step, for example "delete the first 3 rows, remove totals, fix dates, remove duplicates".
{{output_spec}}
What the clean file must look like: columns, order, date and number formats, file name.
{{setup}}
For example "Python 3.12 on Windows; pandas is installed" or "no extra packages allowed".
{{file_locations}}
Where the export lands and where the clean file should go, for example "Downloads folder; a Clean folder on the shared drive".
{{max_lines}}
The longest script you are comfortable maintaining, for example 120.

Why it works

  • What to avoid. The script never overwrites the original and adds no steps you did not list, so running it cannot lose data you meant to keep.
  • What good looks like. A printed summary of rows removed and values changed lets you trust each run without checking the whole file.
  • If unsure. Ambiguous steps come back as questions and a commented placeholder, rather than as code that decides what a duplicate is.

How to use it

  1. Press Fill in variables and type your details into each blank. What you type stays in this browser.
  2. Copy the filled prompt into the AI tool you already use, such as ChatGPT, Claude or Gemini, or open it in the Grader or the Prompt Tester here.
  3. Before you rely on it, try it on three or four real examples. The Prompt Tester runs them all at once and shows which ones go wrong.
Use it from code

Get this prompt as JSON from the free REST API, with your own text in the blanks, or let an AI assistant fetch it through the MCP server. No key.

curl -s https://thinkhard.si/api/v1/prompts/python-csv-cleanup-script

With the MCP server added to Claude, ChatGPT, Cursor or VS Code, call get_prompt with {"prompt": "python-csv-cleanup-script"}, or just ask for it by name.