Reputation: 521
I have 2 dataframes with the same columns and content, however one of the columns items
contains a list of lists and, although they match in both dataframes, assert_frame_equal
returns false and says they are not.
Is there a way to bypass this or not have it compare this column in this case?
Upvotes: 1
Views: 2249
Reputation: 13488
Although I can't reproduce your problem with Pandas 1.4.1, here is one way to exclude columns from equality comparison:
import pandas as pd
from pandas.testing import assert_frame_equal
df1 = pd.DataFrame(
{
"id": [1, 2, 3],
"items": [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
}
)
df2 = pd.DataFrame(
{
"id": [1, 2, 3],
"items": [[1, 2, 3], [4, 5, 6], [7, 8, 10]],
}
)
assert_frame_equal(df1.drop(columns=["items"]), df2.drop(columns=["items"]))
# No AssertionError exception raised
Upvotes: 2