I have two dataframes df1 and df2.
np.random.seed(0)
df1= pd.DataFrame({'key': ['A', 'B', 'C', 'D'],'id': ['2', '23', '234', '2345'], '2021': np.random.randn(4)})
df2= pd.DataFrame({'key': ['B', 'D', 'E', 'F'], 'id': ['23', '2345', '67', '45'],'2022': np.random.randn(4)})
key id 2021
0 A 2 1.764052
1 B 23 0.400157
2 C 234 0.978738
3 D 2345 2.240893
key id 2022
0 B 23 1.867558
1 D 2345 -0.977278
2 E 67 0.950088
3 F 45 -0.151357
I want to have unique keys. If key found already just update the key else insert new row. I am not sure if I have to use merge/concat/join. Can anyone give insight on this please?
Note:I have used full outer join, it returns duplicate columns. Have edited the input dataframes after posting the question.
Thanks!