0

I got two dataframes:

DF1: Index(['Name', 'Timestamp'], dtype='object') // 34424 rows × 2 columns

DF2: Index(['Name', 'Description'], dtype='object') // 103 rows × 2 columns


I want to replace the values in DF1["Name"] with the corresponding Description in DF2["Description"]


I tried the following code:

DF1['Name'] = DF2['Name'].map(DF1_index('Name')['Description'])
DF1

Error: "Description"
Subbu VidyaSekar
  • 2,503
  • 3
  • 21
  • 39

1 Answers1

0

You can use merge for that:

df_merged = DF1.merge(DF2, on=["Name"], how="left")

If you want to keep the original index (DF2 has to have unique "Name" values though):

df_merged = DF1.reset_index().merge(DF2, on=["Name"], how="left").set_index("index")
Andreas
  • 8,694
  • 3
  • 14
  • 38