I have two dfs, df1 is like,
primary_key code amount
220492763 763 32.41
213274768 764 23.41
226835769 766 88.41
224874836 7766 100.31
219074759 74836 111.33
df2 is like,
primary_key code amount
213274768 764 24.41
224874836 7766 101.31
217774816 768 123.43
222176762 798 111.44
219374759 24774 134.56
I like to use df2 to update df_1 based on the same primary_key, and for the rest of rows in df2, append them to the end of df1, so the result looks like,
primary_key code amount
220492763 763 32.41
213274768 764 24.41
226835769 766 88.41
224874836 7766 101.31
219074759 74836 111.33
217774816 768 123.43
222176762 798 111.44
219374759 24774 134.56
have tried to use
df1.set_index('primary_key').combine_first(df2.set_index('primary_key')).reset_index()
but the two dfs mixed together, I am wondering how to fix it.