|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
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[:, ['语文', '数学', '英语', '历史', '政治', '地理', '生物']] |
|