Suite of pandas utilities including a DataFrame comparison report builder.
Project description
pandascompare
pandascompare
is a Python package designed to compare DataFrame
objects, enabling you to quickly identify the differences between two datasets.
Installation
pip install pandascompare
Main Features
The PandasCompare
class compares any two DataFrame
objects along the following dimensions:
Rows
➔ discrepancies with respect to the join key(s) specified via thejoin_on
argument.Columns
➔ name differences or missing columns.Values
➔ data that differs in terms of value or type.
Example Usage
Please refer to the documentation within the code for more information.
Imports
from pandascompare import PandasCompare
Create DataFrames
First, let's create two sample DataFrame
objects to compare.
import pandas as pd
import numpy as np
# February Data
left_df = pd.DataFrame({
'id': [1, 2, 3],
'date': [pd.to_datetime('2024-02-29')] * 3,
'first_name': ['Alice', 'Mike', 'John'],
'amount': [10.5, 5.3, 33.77],
})
# January Data
right_df = pd.DataFrame({
'id': [1, 2, 9],
'date': [pd.to_datetime('2024-01-31')] * 3,
'first_name': ['Alice', 'Michael', 'Zachary'],
'last_name': ['Jones', 'Smith', 'Einck'],
'amount': [11.1, np.nan, 14],
})
Compare DataFrames
Next, we will initialize a PandasCompare
instance to perform the comparison. Please consult the in-code documentation for a comprehensive list of available arguments.
pc = PandasCompare(
left=left_df,
right=right_df,
left_label='feb',
right_label='jan',
join_on='id',
left_ref=['first_name'],
include_delta=True,
verbose=True,
)
Export to Excel
Finally, let's export the compare report to an Excel file to view the results.
pc.export_to_excel()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pandascompare-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93bee2f3c0d1e566181ac37ab59c486fb546311b6ad4f86bec7f9b12ad56126c |
|
MD5 | 2a264bbd73f867e1bdba3e3bd20acc57 |
|
BLAKE2b-256 | f71967f5293b5853d76ce6b978dae4ef59a9deebacecc87a74f34f0e4deb2ee5 |