|
- import openpyxl
- import os
- wb = openpyxl.load_workbook('英雄联盟人物.xlsx', data_only=True)
- ws = wb.worksheets[0]
- rngs = list(ws.values)
- d = {}
- a = 3 #需要拆分的列号
- for row in rngs[1:]:
- if row[a] in d.keys():
- d[row[a]] += [row]
- else:
- d.update({row[a]: [row]})
- for k, v in d.items():
- nwb = openpyxl.Workbook()
- nws = nwb.active
- nws.title = k
- nws.append(rngs[0])
- for r in v:
- nws.append(r)
- os.makedirs("统计汇总表", exist_ok=True)
- nwb.save('统计汇总表/'+k+'.xlsx')
复制代码
按照某一列分类拆分
|
|