0

I am new in python and pandas, and I´m trying to insert the values from df2 ['lp'] for each ['wellname'], into df1. The problem is that I am not able to insert each value in the correct place.

I have tryed using df.groupby , df.mask, df.where, but there is something that I am doing wrong.

df1 = 

wellname    MD
AbC-2062(h) 0
AbC-2062(h) 10
AbC-2062(h) 60
AbC-2062(h) 70
AbC-2062(h) 80
AbC-2062(h) 90
AbC-2016(h) 5480
AbC-2016(h) 5490
AbC-2016(h) 5500
AbC-2016(h) 5510
AbC-2016(h) 5520
AbC-2016(h) 5530


df 2 = 

wellname    lp
AbC-2013(h) 3126
AbC-2014(h) 3120
AbC-2015(h) 3152
AbC-2016(h) 3244
AbC-2029(h) 3187
AbC-2030(h) 3185
AbC-2032(h) 3154
AbC-2033(h) 3200
AbC-2061(h) 3209
AbC-2062(h) 3198
AbC-2063(h) 3255


Expected output = 

wellname    MD  lp
AbC-2062(h) 0   3198
AbC-2062(h) 10  3198
AbC-2062(h) 60  3198
AbC-2062(h) 70  3198
AbC-2062(h) 80  3198
AbC-2062(h) 90  3198
AbC-2016(h) 54  3244
AbC-2016(h) 54  3244
AbC-2016(h) 55  3244
AbC-2016(h) 55  3244
AbC-2016(h) 55  3244
AbC-2016(h) 55  3244
Papu
  • 121
  • 1
  • 1
  • 7

1 Answers1

0

Run:

pd.merge(df1, df2, on=['wellname'], how='left')

Merging mode both (as suggested in one of comments) is wrong.

Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41