0

I want to use the column 'Qual' in Table 1 and categorise them according to the 'Level' in Table 2 in a separate worksheet, further displaying a separate column 'Qual level' of those levels in table 1

Table1:

ID Qual
1234 a
3454 b
2767 c
2098 a

Table2:

Qual level
a AA
b BB
c CC

Final output required:

ID Qual Qual Level
1234 a AA
3454 b BB
2767 c CC
2098 a AA

this is what I have tried so far:

df.groupby(['Qual','Level'])['Qual Level']

its been giving me an error and im not sure if this is the right method.

Jibran Khatib
  • 57
  • 2
  • 8

2 Answers2

1

This is a typical join operation. You can use pd.merge:

new_df = df.merge(other_df, on='Qual', how='left')

Then to rename the level column,

new_df = new_df.rename(columns={'level': 'Qual Level'})

rcshon
  • 907
  • 1
  • 7
  • 12
0

You can try pd.merge

df1['Qual Level'] = df1.merge(df2, on='Qual', how='left')['level']
print(df1)

     ID Qual Qual Level
0  1234    a         AA
1  3454    b         BB
2  2767    c         CC
3  2098    a         AA
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52