0

I have two dataframes:

df_1:

id category 
0  a
1  a
2  a
3  a
4  b
5  c
6  c

df_2

category sentence
a        "first category"
b        "second category"
c        "third category"

I would like to add the sentence value of df_2 sentence column in df_1 everytime we found same category on each dataframe.

I tried inner with merge but not working. How can I do it ? I don't know if I have to merge or map values.

Expected output:

id category sentence
0  a        "first category"
1  a        "first category"
2  a        "first category"
3  a        "first category"
4  b        "second category"
5  c        "third category"
6  c        "third category"
codelifevcd
  • 175
  • 1
  • 10

1 Answers1

0

This should work -

pd.merge(left=df1, right=df2, left_on="category", right_index=True)

Ananay Mital
  • 1,395
  • 1
  • 11
  • 16