How To Efficiently Replace Items Between Dataframes In Pandas?
I have 2 df df = pd.DataFrame({'Ages':[20, 22, 57], 'Label':[1,1,2]}) label_df = pd.DataFrame({'Label':[1,2,3], 'Description':['Young','Old','Very Old']}) I want to replace the la
Solution 1:
Use Series.map
with Series
by label_df
:
df['Label'] = df['Label'].map(label_df.set_index('Label')['Description'])
print (df)
Ages Label
0 20 Young
1 22 Young
2 57 Old
Post a Comment for "How To Efficiently Replace Items Between Dataframes In Pandas?"