how to ignore index comparison for pandas assert frame equal

For those who came to this question because they're interested in using pd.testing.assert_series_equal (operates on pd.Series), pandas 1.1.0 has introduced an argument check_index:

import pandas as pd
s1 = pd.Series({"a": 1})
s2 = pd.Series({"b": 1})
pd.testing.assert_series_equal(s1, s2, check_index=False)

This argument does not yet exist for pd.testing.assert_frame_equals.


If you really don't care about the index being equal, you can drop the index as follows:

assert_frame_equal(d1.reset_index(drop=True), d2.reset_index(drop=True))

Index is part of data frame , if the index are different , we should say the dataframes are different , even the value of dfs are same , so , if you want to check the value , using array_equal from numpy

d1 = pd.DataFrame([[1,2], [10, 20]], index=[0,2])
d2 = pd.DataFrame([[1, 2], [10, 20]], index=[0, 1])
np.array_equal(d1.values,d2.values)
Out[759]: True

For more info about assert_frame_equal in git

Tags:

Python

Pandas