Articles

How do you reconcile two Excel files with pandas?

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.

The code

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.

What it finds

Calder Lane Credit (fictional) against its servicer, 2026-09-30.
ItemValue
Loans in both files45
Missing at the servicer1
Breaks above $1.002
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.

Prove that the exceptions explain the gap

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.

Sources

  1. Julian R. Sterling, Python & pandas for Finance (course, 2026): running case Calder Lane Credit, fictional
  2. pandas documentation: merge (validate, indicator), groupby, cut, read_excel (consulted November 2026)
  3. Basel Committee on Banking Supervision, Guidelines on prudent treatment of problem assets (2017)

Calder Lane Credit and its loans are fictional; the data were generated by code. Educational material, not investment advice. Prepared with AI assistance.

Learn Python and pandas on a real loan book

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 module 1 free →

FAQ

How do you compare two Excel files in pandas?

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.

Why use an outer merge to reconcile?

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.

What tolerance should a reconciliation use?

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.

Related