0

I have two data frames, let's say

df1

UserID  val1 val2
1a      20   36.5
2b      22   39.
4d      NA   NA

df2

UserID  top1 top2
2b      328. 95.
3c      1.1  2.2
1a      3    NA

My expected result is

df3

UserID  val1  val2  top1  top2
2b      22    39.   328.  95.
1a      20    36.5  3     NA

Everytime I try to do this, I either wind up with excess rows, or excess columns (UserID appearing twice) and I'm not sure what I'm doing wrong.

My most recent attempt was

pd.concat( [df1, df2], axis=1, join_axes=['UserID'] )

Thanks

Jibril
  • 967
  • 2
  • 11
  • 29
  • 1
    Have you tried `df1.merge(df2, on='UserID')`? If this doesn't work, please explain why and someone will reopen your question. In the meanwhile, I recommend reading this: https://stackoverflow.com/questions/53645882/pandas-merging-101 – cs95 Mar 25 '19 at 23:49
  • This worked. Is there a good resource that can provide visuals on this that I can refer to? I thought each attempt I did would work and while I understand now why some dont, I do not fully get why others do not. Thanks! Oh the link you provided did just that. That never showed up in my googling! Thanks! – Jibril Mar 25 '19 at 23:52
  • 1
    Looks like you figured it out. Do go through the post and upvote if you find it helpful. Thanks. – cs95 Mar 25 '19 at 23:54

0 Answers0