1df1 = df.set_index(['number','class']).unstack().swaplevel(0,1,1).sort_index(1)
2
3print (df1)
4class A B
5 english math english math
6number
71 40 90 87 67
82 21 20 89 89
93 68 50 54 79
104 89 30 21 45
115 90 57 23 23
12