0

I have two dataset having one column in common, User. However one dataset, df2, has user with no duplicates, while df1 has all the users.

**df1**

User          Text
carl_22       bla bla bla
Renoir_J54    bla bla bla 1
David         bla bla bla 2
carl_22       bla bla bla 3
David         bla bla bla 4
...


**df2**

User          Value
carl_22       43
Renoir_J54    23
David         99
...

I would like to assign to each user in df1 the corresponding Value in df2:

User          Text              Value
carl_22       bla bla bla       43
Renoir_J54    bla bla bla 1     23
David         bla bla bla 2     99
carl_22       bla bla bla 3     43
David         bla bla bla 4     99
...

I used pd.concat([df1, df2], axis=1, join='inner') but the output is different from my expected one. I do not know if I did something wrong: maybe because User, Text in df1 and User, Value in df2 are columns and not indices, or in the use of concat.

Can you please tell me if you spot any issue within my code?

1 Answers1

2

You need merge

pd.merge(df1, df2,how='inner')
Yash
  • 1,271
  • 1
  • 7
  • 9