Python+Pandas:
import pandas as pd
df = pd.read_excel('pandas exercise/sample334.xlsx', usecols='a:i', index_col=[0, 1])
grouped = df.stack().reset_index(level=2).groupby('level_2')
lst = []
for name, group in grouped:
group = group[0].nlargest(30)
group = group.reset_index()
group['名次'] = group.index + 1
mi = pd.MultiIndex.from_tuples([(name, i) for i in ['名次', '姓名', '班级', '成绩']])
group = group.iloc[:, [3, 0, 1, 2]]
group.columns = mi
lst.append(group)
df1 = pd.concat(lst, axis=1)
df1 = df1.loc[:, ['语文', '数学', '英语', '历史', '政治', '地理', '生物']] |