pandas df equals code example

Example 1: dataframe equals pandas

>>> exactly_equal = pd.DataFrame({1: [10], 2: [20]})
>>> exactly_equal
    1   2
0  10  20
>>> df.equals(exactly_equal)
True

Example 2: pandas df exact equals

>>> 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]})
>>> df3 = pd.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]})
>>> assert_frame_equal(df1, df2)
False
>>> assert_frame_equal(df2, df3)
True
>>> assert_frame_equal(df1, df2, check_dtype=False)
True

Example 3: pandas two dataframes equal

>>> df = pd.DataFrame({1: [10], 2: [20]})

>>> exactly_equal = pd.DataFrame({1: [10], 2: [20]}) # Note the same as above

>>> df.equals(exactly_equal)
True
# Two are the same hence true. If not would be false