Shubham Korade
Shubham Korade

Reputation: 194

How to create dataframe using two dataframe using pandas

I have two dataframe 'df1' and 'df2'

df1=   a       b
       1       such as
       2       who I'm

df2=   a       keyword
       1       such
       1       as
       2       who
       2       I'm

Based on this two dataframe I want to create following dataframe

result =   a           keyword
           such as     such
           such as     as
           who I'm     who
           who I'm     I'm

Upvotes: 0

Views: 35

Answers (1)

mozway
mozway

Reputation: 260600

IIUC, just perform a replacement with map:

df2['a'] = df2['a'].map(df1.set_index('a')['b'])

Upvotes: 1

Related Questions