'Pandas groupby and get nunique of multiple columns in a dataframe

I have a dataframe like as below

stu_id,Mat_grade,sci_grade,eng_grade
1,A,C,A
1,A,C,A
1,B,C,A
1,C,C,A
2,D,B,B
2,D,C,B
2,D,D,C
2,D,A,C

tf = pd.read_clipboard(sep=',')

My objective is to

a) Find out how many different unique grades that a student got under Mat_grade, sci_grade and eng_grade

So, I tried the below

tf['mat_cnt'] = tf.groupby(['stu_id'])['Mat_grade'].nunique()
tf['sci_cnt'] = tf.groupby(['stu_id'])['sci_grade'].nunique()
tf['eng_cnt'] = tf.groupby(['stu_id'])['eng_grade'].nunique() 

But this doesn't provide the expected output. Since, I have more than 100K unique ids, any efficient and elegant solution is really helpful

I expect my output to be like as below

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source