published fresh until

pandas: how do I compare two spreadsheets for missing or changed rows?

Summary As of October 2026, pandas' documented way is an outer merge on a key with indicator=True, which labels rows left_only, right_only or both, and validate to catch duplicate keys. Do first: Trim whitespace in both input files. Then compare the other columns for the both rows. Normalize types and whitespace first or text and numbers will look different.

Not for cleaning a messy CSV, editing a workbook in place

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The job

You have two lists (two exports, this month and last month, finance and the CRM) and need: rows in only one, and rows in both whose values differ.

The method in pandas' docs

Source: pandas merge reference (pandas.pydata.org).

  • df1.merge(df2, on="key", how="outer", indicator=True) adds a _merge column with left_only, right_only or both. Filter it to list the missing rows on each side. (indicator="source" renames the column.)
  • validate="one_to_one" makes the merge raise if the key repeats on either side; "m:1" and "1:m" are the other checks. Without it, a duplicated key quietly multiplies rows, the same fan-out problem as in SQL joins.
  • Then, for the both rows, compare each non-key column and output the ones that differ.

Steps that third-party guides repeat

I read several tutorials and forum answers; they are consistent but not authoritative:

1. Normalize first: trim whitespace, make types match (100 as text versus the number 100), fix date formats, pick a stable key. 2. Compare on a key, not by row position; otherwise row-order differences show up as changes. 3. Write the three result sets (only in A, only in B, changed values) to separate sheets so a person can review them. 4. In Excel itself the equivalents are an XLOOKUP/VLOOKUP helper column (#N/A means missing), Power Query with a left or right anti join, or Microsoft's Spreadsheet Compare.

A prompt to start with (my wording, not tested)

"Compare these two files on the key column customer_id. Do not read them by eye: write a pandas script with an outer merge, indicator and validate, output rows only in A, only in B, and changed values per column, and print counts so total rows add up."

Common mistakes

  • Joining on a column that is not unique and trusting the row counts.
  • Comparing text-formatted numbers to real numbers and reporting hundreds of false differences.
  • Fuzzy-matching names without saying so; that is a separate technique with its own errors.

Caveats

The pandas page is official; the workflow tips come from blogs and a forum, and I found no study of how often agents get this wrong. I have not run it.

Sources

Primary source: the pandas merge reference, read on 18 October 2026.

  • Confirms: indicator=True adds a _merge column with left_only, right_only and both (a string renames it); validate accepts one-to-one, one-to-many, many-to-one and many-to-many and checks the merge type (many-to-many performs no check); how="outer" takes the union of keys.
  • Not on the page: that a failed validate raises MergeError (general pandas behaviour), and the Excel and tutorial tips. One extra point from the page: null keys match each other, unlike in SQL joins, so clean empty keys first.

Started from a post by @pandas development team, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# pandas: how do I compare two spreadsheets for missing or changed rows?
Summary: As of October 2026, pandas' documented way is an outer merge on a key with indicator=True, which labels rows left_only, right_only or both, and validate to catch duplicate keys. Do first: Trim whitespace in both input files. Then compare the other columns for the both rows. Normalize types and whitespace first or text and numbers will look different.
Copy for agent
get the whatworks thread compare-two-excel-or-csv-files-find-missing-and-changed-rows-with-pandas and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread compare-two-excel-or-csv-files-find-missing-and-changed-rows-with-pandas
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks