How Do You Turn a ChatGPT Data Cleanup Into a Reusable Script?
When a cleanup looks right, ask ChatGPT to put every step into one script that takes a file path, leaves the original alone and prints a short report on what it changed. Download it and run it on last month's file before you trust it. Next month, you run the script instead of redoing the chat.
Turn the cleanup we just did into one reusable Python script. Requirements: - Run it as: python clean.py [input file] [output file] - Never change the input file. - Use pandas. List any other package you need, and pin versions in a comment. - Put settings at the top: [date format, column aliases, currency rules]. - Include every step we agreed on, including [specific fixes, such as dropping the summary rows]. - Don't invent values. Leave blanks blank, and keep [source row ID column]. - If a required column is missing or a new category appears, stop and print an error instead of guessing. - At the end, print the row count in and out, plus how many rows were changed, removed or flagged. Then run it on the file in this chat and confirm that it gives the same totals as our earlier result. Give me a download link for the script.
- 1Clean it in chat
- 2Ask for one script
- 3Test it on last month's file
Try it now
- 1At the end of a cleanup chat, paste the prompt above, then download the script and the cleaned file.
- 2On your computer, run
python clean.py last-month.csv cleaned.csvusing a different month's export. - 3Compare the row counts to the report it prints, and open a few flagged rows. It worked if it's right on a file it never saw, or stops with a clear error when the format changes.
Use it when
Exports that come back on a schedule with the same problems, such as a monthly CRM dump or weekly ad report. It also makes sense when someone else needs to repeat the job or when a client asks how a number was produced.
Skip it when
A one-time cleanup, since writing and testing a script takes longer than checking the result. And if nobody on your team can run Python, a ChatGPT scheduled task or a saved prompt may be more practical. Go, Plus and Pro include scheduled tasks. OpenAI suggests refining the prompt in a normal chat first, then scheduling it there.
Why it works
A chat gives you a result, but a script gives you the steps. OpenAI's dataset use case says that if you need reusable scripts or a notebook, you should ask ChatGPT to use your existing Python environment or create a small reproducible one, keeping source files unchanged and saving the analysis separately. It names pandas for cleaning and joins.
OpenAI's cleaning use case provides the safety rules: a cleaned copy with the original left unchanged, source row IDs preserved where possible, and a data-quality note listing rows changed, removed or not cleaned with confidence.
Download files soon. In the API, OpenAI says Code Interpreter containers expire after 20 minutes of inactivity, and files and in-memory state are lost. ChatGPT's own limits weren't on a page that could be opened, so don't assume a file will wait for you there.
Example
Your monthly CRM export has dates in two formats, currency with dollar signs and commas, several spellings of each region, and summary rows mixed in. After fixing this in chat, you ask for clean.py. Say that in March, a new region called "EMEA-2" appears. The script stops and names it, so you add it to the aliases at the top in ten seconds. A chat might have quietly lumped it in with something else, and you'd never have noticed.
Going further
Codex can make this repeatable. OpenAI's Save workflows as skills use case starts with "Use $skill-creator to create a Codex skill that" and asks for a working example, scripts or commands to reuse and what good output looks like. You can then invoke $skill-name later on and ask Codex to add corrections to it. To automate it, codex exec runs without the interactive interface. OpenAI's page says it runs in a read-only sandbox by default, so writing the cleaned file needs --sandbox workspace-write, and commands must run in a Git repo unless you pass --skip-git-repo-check.
Common mistakes
- Hardcoding one month's file name, column order or date range, so the script breaks on next month's file.
- Asking for the script without running it on a second file. A script that works on the data it was written from proves little.
- Letting it overwrite the source. Require separate input and output paths.
- Silently dropping rows that don't match. Print them, or a new category will vanish without anyone knowing.
Sources
- OpenAI use case: Analyze datasets and ship reports
- OpenAI use case: Clean and prepare messy data
- OpenAI API docs: Code Interpreter
- ChatGPT Learn: Prompting
- ChatGPT pricing
- OpenAI use case: Save workflows as skills
- ChatGPT Learn: Non-interactive mode
Checked 6 November 2026. Products change often, so confirm details with the vendor.