Pandas: rank

#list highest score and studentid for each student
df['rk'] = df.groupby('studentid')['scores'].rank(method='max',ascending=False).astype(np.int64)
df[df['rk'] == 1][['studentid','major']]

https://pandas.pydata.org/docs/