Disclosure: I make ThreeWayMatch at Murabyte, which is mentioned at the end. Written with AI assistance and reviewed by Murabyte.

Paying the same supplier invoice twice is one of the most common accounts payable mistakes. The invoice number is often retyped slightly differently, so a plain duplicate check misses it. Here is a small pandas script that catches the usual cases.

The data

Export your invoices to a CSV with these columns: supplier, invoice_no, date, amount.

Normalise the invoice number first

INV-0042, inv 42 and 0042 are often the same invoice. Strip everything except letters and digits, lower-case it and remove leading zeros.

import re import pandas as pd df = pd.read_csv("invoices.csv", parse_dates=["date"]) def norm(s): s = re.sub(r"[^a-z0-9]", "", str(s).lower()) return s.lstrip("0") df["inv_key"] = df["invoice_no"].map(norm) 

Check 1: same supplier and same normalised number

dup_no = df[df.duplicated(["supplier", "inv_key"], keep=False)] 

Check 2: same supplier, same amount, close dates

A resubmitted invoice sometimes gets a new number. Look for the same amount from the same supplier within a few days.

df = df.sort_values(["supplier", "amount", "date"]) gap = df.groupby(["supplier", "amount"])["date"].diff().dt.days dup_amt = df[(gap <= 7) | (gap.shift(-1) <= 7)] 

Review, do not auto-reject

Some matches are legitimate, such as a monthly fee that repeats at the same amount. Treat the output as a list to review before you pay, not a list to delete.

pd.concat([dup_no, dup_amt]).drop_duplicates().to_csv("review.csv", index=False) 

Where a tool helps

Duplicates are only one of the checks before payment. ThreeWayMatch is an offline Windows app that compares purchase orders, goods receipts and supplier invoices from CSV or Excel, and flags price, quantity and possible duplicate invoices. It is $49 with a 15-day trial: https://murabyte.gumroad.com/l/threewaymatch