Data Cleaning Script Walkthrough With Assertions and a Change Log
Write a pandas cleaning script that checks itself and records what it changed.
The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.
[VERIFY] is an editorial flag, not a blank to fill. Wherever the prompt shows [VERIFY], check that item against a reliable source before you use it.
Write a pandas cleaning script for my data and explain each step. Columns, types and known problems: [COLUMNS_AND_PROBLEMS]. A sample of five rows (invented or anonymised): [SAMPLE_ROWS]. Business rules the data must satisfy (for example amounts are not negative, order_date is not after ship_date): [BUSINESS_RULES]. Output file format: [OUTPUT_FORMAT]. Produce a script with sections: read with explicit dtypes and date parsing; profile (shape, missing counts, duplicates); clean (strip whitespace, standardise case, parse dates, convert currencies or units, handle missing values with rules I choose, never silently drop rows); validate with assertions or explicit checks that print readable errors; and write the output. Add a change log DataFrame that records each rule, the number of rows affected, and a sample of before-and-after values. Explain each pandas function used in one line and give the expected output of the profile step on my sample. Include a test with a deliberately bad row to show the validation failing. Run nothing on my behalf. Mark pandas behaviours that differ by version as [VERIFY] and keep the script compatible with a recent stable version.
Fill in before use
Optional: type your details and the prompt above updates. Nothing is saved or sent.
Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.