0

Let's say I have data similar to the following: df:

Student Week 1 Grade
John 93
Sally 72
James 93
Jim 72

df1:

Student Week 2 Grade
John 87
James 93
Jim 72

I want to merge these two, and I figure I should use an outer join, but this is what I'm getting:

Student Week 1 Grade Student Week 2 Grade
John 93 John 87
Sally 72 James 93
James 93 Jim 72
Jim 72 NaN NaN

This is what I'd like to get:

Student Week 1 Grade Week 2 Grade
John 93 87
Sally 72 NaN
James 93 93
Jim 72 72

The ordering of Student varies in each DataFrame, and there are some names in df that are not present in df1.

Thanks for your help!

  • If I use how='left', it is dropping rows that are present in one dataframe that are not present in another. –  Jul 18 '21 at 22:55
  • 1
    `df.merge(df1, on='Student', how='outer')` works for this example as well. – Henry Ecker Jul 18 '21 at 22:57
  • `df.merge(df1, on='Student', how='outer')` ended up working. I thought I had tried that but apparently I did not. Thank you! –  Jul 18 '21 at 23:10

0 Answers0