I am trying to add a column to a pandas dataframe (df1) that has a unique identifier ('id') column from another dataframe (df2) that has the same unique identifier ('sameid'). I have tried merge, but I need to only add one specific column ('addthiscolumn') not all of the columns. What is the best way to do this?
print df1 'id' 'column1' 0 aaa randomdata1 1 aab randomdata2 2 aac randomdata3 3 aad randomdata4 print df2 'sameid' 'irrelevant' 'addthiscolumn' 0 aaa irre1 1234 1 aab irre2 2345 2 aac irre3 3456 3 aad irre4 4567 4 aae irre5 5678 5 aad irre6 6789 Desired Result
print df1 'id' 'column1' 'addthiscolumn' 0 aaa randomdata1 1234 1 aab randomdata2 2345 2 aac randomdata3 3456 3 aad randomdata4 4567
df1.merge(df2, left_on='id', right_on='sameid')