Read both, merge them with how="outer" and indicator=True, compute the difference, and classify every row: OK, break, or missing on one side.
To reconcile two Excel files in pandas, read both with pd.read_excel, merge them on the key with how="outer" and indicator=True, subtract the amounts, and give every row a status: OK when the difference is within a tolerance, a break when it is not, missing when the key is on one side only. In this example, a lender's book of 46 loans against its servicer's report, the method finds 2 breaks and 1 missing loan, and what is left unexplained is $0.02 of rounding.
def reconcile():
ours = book()[["balance"]].reset_index() # columns loan_id, balance
theirs = pd.read_excel(DATA / "Servicer_Report.xlsx", sheet_name="Balances", skiprows=2)
r = ours.merge(theirs, on="loan_id", how="outer", indicator=True)
r["difference"] = r["servicer_balance"] - r["balance"]
r["status"] = "OK"
r.loc[r["difference"].abs() > TOL, "status"] = "Break"
r.loc[r["_merge"] == "left_only", "status"] = "Missing at servicer"
r.loc[r["_merge"] == "right_only", "status"] = "Missing in our book"
return r.drop(columns="_merge")
The servicer's file has two title lines above the header, hence skiprows=2. An inner merge would be a mistake: the loans missing on one side would disappear from the result instead of showing as exceptions.
| Item | Value |
|---|---|
| Loans in both files | 45 |
| Missing at the servicer | 1 |
| Breaks above $1.00 | 2 |
| Our total | $46,569,173.56 |
| Servicer total | $46,300,266.88 |
| Unexplained after the exceptions | $0.02 |
Each exception has a reading. One break equals the principal of the loan's last payment: the servicer has not posted it yet. The other is a round $9,000: a keying error. The missing loan is 60 to 89 days past due in the book: a transfer to a workout team is a common reason, and a question to ask before any adjustment.
Start from the difference of the two totals, remove the breaks and add back the missing loans: what remains must be zero or explained. Here it is $0.02, the rounding of 45 balances to the cent. Without that last line, a reconciliation is a list of differences, not a proof.
Calder Lane Credit and its loans are fictional; the data were generated by code. Educational material, not investment advice. Prepared with AI assistance.
31 lessons from zero: import, clean and join the files of a finance team, build payment schedules, age arrears, compare vintages, measure yields, draw charts, write the Excel report and reconcile it, on a 60-loan portfolio. Start and solution files, notebooks, exercises and a certificate exam ($199).
Read both with read_excel, merge them on a key column with how='outer' and indicator=True, and compare the value columns row by row.
Because it keeps the rows of both files. An inner merge drops the rows missing on one side, which are often the most important exceptions.
One that matches the precision of the data, such as one dollar for balances rounded to the cent, so that rounding does not show as breaks.