Pandas DataFrame | equals method
Start your free 7-days trial now!
Pandas DataFrame.equals(~)
checks whether two DataFrames are identical, that is, all their respective values, column labels and index names are equal, and have the same data type.
The one exception is that although the column labels must share the same value, their data type need not match for the method to return True
. Check the example below for clarification.
Parameters
1. other
| Series
or DataFrame
The other DataFrame that you want to compare with.
Return value
A single boolean indicating whether two DataFrames are equal.
Examples
Basic usage
df1 = pd.DataFrame({"A":[3,4],"B":[5,6]})df2 = pd.DataFrame({"A":[3,4],"B":[5,6]})df1.equals(df2)
True
Exception
Consider the following DataFrame:
df = pd.DataFrame({1: [3,4]})df
10 31 4
Suppose the other DataFrame we wanted to compare with was:
df_other = pd.DataFrame({1.0: [3,4]})df_other
1.00 31 4
Here, we see that the two DataFrames are identical, except the column label's type (i.e. int
vs float
).
Now, calling our equals(~)
method gives:
df.equals(df_other)
True
We see that the two DataFrames are still considered to be equal regardless.