0

I have df1:

     id  value1 value2
 0   A_1  123   878
 1   A_2  251   356
 2   A_3  222   332

and df2:

    id
0   A_2
1   A_3
2   A_3
3   A_1
4   A_1
5   A_4

desired output:

    id   value1 value2
0   A_2    251      356
1   A_3    222      332
2   A_3    222      332
3   A_1    123      878
4   A_1    123      878
5   A_4    NA        NA

is there any fastest way to do this? Thanks!

rebel095
  • 81
  • 6

1 Answers1

1

You should be able to accomplish this with a left-join:

df2.merge(df1, on='id', how='left')

See this blog post for more details, or the official docs.

Will Da Silva
  • 6,386
  • 2
  • 27
  • 52