|
建议用python+pandas:
import pandas as pd
import pathlib
this_dir = pathlib.Path('./Pandas exercise').resolve()
dfs = []
for path in (this_dir / 'Sample143').rglob('*.xlsx'):
print(f'Reading {path.name}')
if path.name[:4] == '考生名单':
df = pd.read_excel(path, usecols='a:i', skiprows=1, engine='openpyxl')
df.insert(0, column='日期', value=path.name[-13:-5])
dfs.append(df)
df1 = pd.concat(dfs)
df1['班组'] = df1.iloc[:, -1].str.extract('kV(.*)(?:巡|变)')
writer = pd.ExcelWriter(this_dir / 'Sample143/成绩阶段分析.xlsx')
for name in df1['班组'].unique():
df2 = df1[df1.班组 == name].reset_index(drop=True)
df2.insert(0, column='序号', value=df2.index + 1)
df2.iloc[:, :-1].to_excel(writer, name, index=False)
writer.close() |
|