The dullest job at month-end is not issuing invoices; it is reconciliation. Export the bank statement once, export the books once, and someone starts reading line by line: the bank has this entry, does the ledger? This figure is fifty dollars out — a bank charge or a typo? With two or three hundred transactions a month the eyes glaze over, and the worst part is that when it is done you can only say it "roughly ties out"; nobody can name the entries that are genuinely still open.
Reconciliation is exactly the kind of work a computer should do: clear rules, high repetition, no judgement required. Below is a Python and pandas recipe that takes a month of reconciliation from three hours to ten minutes, and produces three reports stating precisely what matched and what genuinely needs a human.
Reconciliation only has three outcomes
Whatever the size of the company, the difference between the bank and the books always falls into three groups:
- Identical amounts — matched, move on.
- Slightly different amounts — usually bank charges, telegraphic transfer fees, exchange-rate differences, or one sale split across two invoices.
- Only on one side — not yet recorded, customer has not paid, cheque not cleared, or the amount was keyed wrongly. These are the ones a human must follow up.
So the goal is not to resolve every difference automatically; it is to clear the first two groups automatically and pass only the third to a person. In practice fewer than ten entries are left for manual review.
Step one: get both CSVs into the same shape
Online banking almost always offers an export of transaction history to CSV, and accounting software or a plain Excel ledger can export the same. Each file only needs three columns: date, description (or reference), amount. Fix the amount convention: money in is positive, money out is negative; thousands separators and bracketed negatives (for example (1,200.00) meaning minus) are cleaned by the script.
Step two: install
openpyxl is only needed to write the Excel output.
Step three: the reconciliation script
Create a folder, put bank.csv and books.csv in it, and add match.py:
Line by line
- load() — reads the CSV and cleans the amount: strips commas, turns brackets into negatives, forces the value to a number and rounds to two decimals. Skip this and nothing ever matches, because "12,500.00" is text, not a number.
- tag() — a company may receive several cheques of the same value in one month, so every amount gets an occurrence number. Without it, two entries of 8,000 match each other four ways (a cartesian product) and the report becomes noise.
- merge(..., indicator=True) — a full outer join on amount plus occurrence. The left frame is the bank, the right is the books, and _merge labels each row both, left_only or right_only, so one table shows all three outcomes.
- merge_asof() — the second pass for "slightly different amounts": match the nearest date within three days, then keep only pairs whose difference is at most 50 dollars. Fee ceilings differ by company; raise it if you send a lot of wire transfers.
Step four: read the three reports
The run prints four numbers, for example "matched exactly 4 / matched within tolerance 1 / bank only 1 / books only 1". Only the last two matter now: bank only is usually unrecorded income or an unposted bank charge; books only is usually a customer who has not paid or a cheque not yet cleared. Export those two tables to Excel and you have the reconciliation list to hand to the accountant or the boss.
Five pitfalls you will hit
- Date format — banks usually export DD/MM/YYYY, hence dayfirst=True; if the file is already YYYY-MM-DD it is unambiguous, but a mix of both must be normalised first.
- Negative notation — banks often use brackets or separate DR and CR columns; leave it inconsistent and you get fake differences of exactly double.
- One entry against many — a customer settling three invoices in one transfer appears as a single total in the bank. Split that by hand; do not force a rule.
- Several entries, same day, same amount — the occurrence number handles most of it; if it is still messy, put the invoice reference in the description and match on that.
- Back up the source files — the script only reads the original CSVs, but keep a copy anyway so you can always re-run.
How much time it actually saves
Take a trading company with 250 transactions a month: manual reconciliation takes about three hours, and usually happens twice, because the first pass turns up a mis-keyed entry that has to be corrected and re-checked. With the script, the first setup takes about half an hour (cleaning the CSV columns, tuning the tolerance); after that each month is two files swapped in and one run, ten seconds later. The only human work left is the handful of rows at the bottom of the report.
Summary
Python Tutorial: reconciliation does not require buying reconciliation software, and it does not require learning an accounting system's API. Two CSVs and about thirty lines of pandas turn "which entries matched and which need following up" into a definite list. The point is not how clever the code is, but how clearly the rules are written: one amount convention, an occurrence number for repeated amounts, and a cap on tolerance. Get those three right and the computer clears ninety per cent of the repetitive work, leaving the remaining ten per cent — judgement and follow-up — which is where a person should be spending time.