0

I have two dataframes:

df1 =

Header: Class , Grade

English , A

df2 =

Header: Class , Teacher

English, Smith

Chinese, Yert

What I need is to overlay a new column entry if there is a match, and if no match, append it to the end such that the output is:

Header: Class, Grade, Teacher

English, A, Smith

Chinese, NaN, Yert

Thank you in advance.

Harry123
  • 49
  • 7

1 Answers1

0

Use:

df = pd.concat([df1.set_index('Class'), df2.set_index('Class')], axis=1).reset_index()

Or:

df = df1.merge(df2, on='Class')
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252