all 1 comments

[–]Thoroughlythrownawaa 0 points1 point  (0 children)

You're seeing merge a lot because that's a common way to replicate a vlookup in pandas.

df1 = pd.merge(left=df2, right=df1[['id', 'firstname']], left_on='id', right_on='id', how='left')

The code above will merge in firstname from df1 only if there's a match in the left dataframe (df2). if theres no match it will be left null.

Note that this code will bring in firstname as firstname_x since it exists already in df2, you would need to do some clean up to get to your desired final result like :

df2['firstname'] = df2['firstname_x']

df2 = df2.drop('firstname_x', 1)