capitalone/datacompy

Pandas, Polars, Spark, and Snowpark DataFrame comparison for humans and more!

DataComPy is an open-source library that compares two datasets (called DataFrames — essentially tables of rows and columns) and tells you how they differ. It was created by Capital One as a modern, more feature-rich alternative to a classic SAS procedure called PROC COMPARE, and it goes beyond a simple "are these equal?" check: it prints statistics and lets you adjust how precise matches must be.

It works with several popular data-processing backends:

  • Pandas — the most widely used Python data-analysis library
  • Polars — a fast, newer alternative to Pandas
  • Spark (both classic and Spark Connect) — a system for processing very large datasets across clusters
  • Snowflake — a cloud data warehouse

The project recently released version 1.0; the older 0.19.x line is no longer maintained.


How to install

Simple installation via either pip or conda. If you need the Spark or Snowflake backends, you install "extras" (e.g., pip install datacompy[spark]).


Two ways to use it

1. Command-line tool

DataComPy ships a command called datacompy compare. This lets you run ad-hoc checks without writing a script, and it can be used in CI pipelines. Example:

datacompy compare --left before.csv --right after.csv --on id

This compares two files and prints a report. You can also save the report as JSON, set tolerance thresholds for numeric columns, and fail a build if any differences appear. The command exits with code 0 if the datasets match, 1 if they differ, and 2 on an error. It accepts CSV, Parquet, and JSON files; a .tsv extension handles tab-separated files. Snowflake tables can be compared directly.

2. Programmatic API (inside Python)

Every compare object exposes a method build_report_data(), which returns a typed ReportData object. This gives you structured access to the comparison results — useful if you're building dashboards, exporting JSON, or doing custom rendering instead of using the plain-text report. The example in the README shows two small Pandas DataFrames being compared by a shared id column; the report object lets you directly read values like the number of unequal rows or the name of a mismatched column, and you can render it as text, save it as HTML, or convert it to a JSON-serializable dictionary.


Contributions

The project welcomes contributions, but requires signing a Contributor License Agreement (CLA) before accepting any code. It follows an open-source code of conduct.

Related

  • Project
  • Project
  • Project
  • Project