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_mergecolumn withleft_only,right_onlyorboth. 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
bothrows, 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=Trueadds a_mergecolumn withleft_only,right_onlyandboth(a string renames it);validateaccepts 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
validateraisesMergeError(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