Skip to content Skip to sidebar Skip to footer

Replace Value In A Specific With Corresponding Value

I have a dataframe called REF with the following structure: old_id new_id 3 6 4 7 5 8 I want to replace all the values that can be found equal to

Solution 1:

Use map:

s = df1.set_index('old_id')['new_id']

df2['old_id'] = df2['old_id'].map(s).fillna(df2['old_id'])

Or slowier solution with replace:

df2['old_id'] = df2['old_id'].replace(s)

Post a Comment for "Replace Value In A Specific With Corresponding Value"