How to check whether two pandas DataFrames are equal and to what extend
Pandas has its own testing methods to check e.g. if two DataFrame objects are equal or not. Here we use pandas.testing.assert_frame_equal to compare two DataFrame objects. df_two is a copy of df_one but with swapped column order, i.e. it is the same content but the order of the columns is different. Applying assert_frame_equal does indeed raise an AssertError with detailed information about what caused the error: 'DataFrame.columns values are different. If we want to check if the content of the two DataFrame objects is equal independent of the order, we can either enforce that both DataFrame objects have the same column order by selecting the order. Or we can set check_like=True in assert_frame_equal to ignore the order of columns.
dependencies: python3.10, pandas==1.4.3
Comments
Post a Comment