Check that left and right DataFrame are equal.
This function is intended to compare two DataFrames and output any differences. It is mostly intended for use in unit tests. Additional parameters allow varying the strictness of the equality checks performed.
First DataFrame to compare.
Second DataFrame to compare.
Whether to check the DataFrame dtype is identical.
Whether to check the Index class, dtype and inferred_type are identical.
Whether to check the columns class, dtype and inferred_type are identical. Is passed as the exact
argument of assert_index_equal()
.
Whether to check the DataFrame class is identical.
Whether to check that the names attribute for both the index and column attributes of the DataFrame is identical.
Specify how to compare internal data. If False, compare by columns. If True, compare by blocks.
Whether to compare number exactly.
Changed in version 2.2.0: Defaults to True for integer dtypes if none of check_exact
, rtol
and atol
are specified.
Compare datetime-like which is comparable ignoring dtype.
Whether to compare internal Categorical exactly.
If True, ignore the order of index & columns. Note: index labels must match their respective rows (same as in columns) - same labels must be with the same data.
Whether to check the freq attribute on a DatetimeIndex or TimedeltaIndex.
Whether to check the flags attribute.
Relative tolerance. Only used when check_exact is False.
Absolute tolerance. Only used when check_exact is False.
Specify object name being compared, internally used to show appropriate assertion message.
See also
assert_series_equal
Equivalent method for asserting Series equality.
DataFrame.equals
Check DataFrame equality.
Examples
This example shows comparing two DataFrames that are equal but with columns of differing dtypes.
>>> from pandas.testing import assert_frame_equal >>> df1 = pd.DataFrame({'a': [1, 2], 'b': [3, 4]}) >>> df2 = pd.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]})
df1 equals itself.
>>> assert_frame_equal(df1, df1)
df1 differs from df2 as column âbâ is of a different type.
>>> assert_frame_equal(df1, df2) Traceback (most recent call last): ... AssertionError: Attributes of DataFrame.iloc[:, 1] (column name="b") are different
Attribute âdtypeâ are different [left]: int64 [right]: float64
Ignore differing dtypes in columns with check_dtype.
>>> assert_frame_equal(df1, df2, check_dtype=False)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4