
In this article
Let’s walk through a real session. The task: every month, the bank statement export has extra header lines, amounts as text with commas, dates in two formats and split debit/credit columns. We want one clean table.
Advertisement
Step 1 β look first
Read sample/statement.csv and show me: the first 15 lines exactly as they are,
how many lines in total, and which line the real column headers are on.
Never let the AI guess the file layout; have it show you.
Step 2 β load correctly
Write clean.py that reads the file starting at the header line you found,
and prints the column names and the first 5 rows as a table.
Step 3 β one rule at a time
Add: convert "Debit" and "Credit" from text like "1,25,000.00" to numbers;
create one Amount column (credit positive, debit negative); drop the two old columns.
Print the total of Amount and the count of rows.
Check the printed total against the closing minus opening balance on the statement. If they match, the conversion is right.
Add: dates come as both 05/04/2026 and 05-Apr-2026. Parse both as day-first
and store as 2026-04-05. Show me any rows that failed to parse.
Step 4 β save and make it reusable
Save to output/statement_clean.xlsx with a header style and column widths.
Make the input file a command-line argument so I can run:
python clean.py statements/april.csv
The finished tool
Typical result: about 60 lines of Python you didn’t type, which turns a 20-minute monthly chore into a 5-second command. Keep the sample and expected files next to it β next month, when the bank changes its format, you will need them.
β οΈ The balance check in Step 3 is what makes this trustworthy. Every tool that touches money needs one number you can verify independently.
β¨ Ask AI about this article
Stuck on a step? Ask a question and the AI answers using this article.
Free Β· AI can be wrong