I have 2 dataframes and i am trying to find number of different value per column:
df 1
-----
id rank value group
0 1 999 A
1 2 3 A
2 3 345 B
3 56 8 C
4 7 54 D
_____
df 2
_____
id rank value group
0 1 111 A
1 2 3 B
2 3 345 B
3 56 11 C
4 7 2 D
5 4 92 E
I have a function to calculate the differences:
def diff_helper(x):
if x[0] == x[1]:
return 'same'
return 'diff'
merged_df = pd.merge(df1, df2, on = 'id')
merged_df.apply(lambda frame: frame.apply(diff_helper, axis=1))
We ignore the last row of df2 because it doesn't overlap with df1. My expected output is
rank : 0
value: 3
group: 1
value is 3 because 999 vs 111, 8 vs 11, 54 vs 2.
group is 1 because A vs B in second row