In my previous question here : How to efficiently replace items between Dataframes in pandas?
I got a solution with map() function that works, but it overrides items that do no match.
In case I have 2 df
df = pd.DataFrame({'Ages':[20, 22, 57, 250], 'Label':[1,1,2,7]})
label_df = pd.DataFrame({'Label':[1,2,3], 'Description':['Young','Old','Very Old']})
I want to replace the label values in df to the description in label_df, but if there is no match between the indexes, keep the original value.
What I am getting with df['Label'] = df['Label'].map(label_df.set_index('Label')['Description'])
{'Ages':[20, 22, 57, 250], 'Label':['Young','Young','Old', nan]}
Wanted result:
{'Ages':[20, 22, 57, 250], 'Label':['Young','Young','Old', 7]}