How to compare two dataframes and filter the different data?

Question:

Currently two dataframes that must be the same, but are of different sizes. How do I compare the two Dataframes, to find the data that are different using pandas?

I couldn’t use df_control.eq()

import pandas as pd

df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
df2 = pd.DataFrame({'col1': [14, 22], 'col2': [32, 22]})
df.eq(df2)

Compare two series

Output:
col1    col2
0   False   False
1   False   True

I practically want to compare the two dataframes with a large amount of data and filter the rows that are different, for data validation

Expected

col1 col2  Verify
1      3    False
2      4    False
14     32   False
22     22   True
Asked By: Zan

||

Answers:

result = pd.concat([df, df2])
ar = result.to_numpy()
result['Verify'] = (ar[:, [0]] == ar).all(axis=1)

Result:

   col1  col2  Verify
0     1     3   False
1     2     4   False
0    14    32   False
1    22    22    True
Answered By: Vladimir Fokow
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.