I have two pandas data frames. The first is:
df1 = pd.DataFrame({"val1" : ["B2","A1","B2","A1","B2","A1"]})
The second data frame is:
df2 = pd.DataFrame({"val1" : ["A1","A1","A1","B2","B2","B2"],
"val2" : [10, 13, 16, 11, 20, 22]})
I would like to merge the two together in a way in which the row ordering from df1 is used and the values from df2 follow this ordering. Ideally, I would like it to look like this:
df_final = pd.DataFrame({"val1" : ["B2","A1","B2","A1","B2","A1"],
"val2" : [11, 10, 20, 13, 22, 16]})
I've tried using the merge function with left_on and right_on, but I don't get the output I'm looking for. Any help would be greatly appreciated.
df2.update(df1)
and then sort vals? – Padraic Cunningham