1.读取数据
import pandas as pd
table = pd.read_excel('path0',sheet_name='sheetName')
2.获取以某字段区分
columns= table ['列名称'].values
table ['indexs'] = columns
table .set_index('indexs',inplace=True)
column= set(columns)
3.处理数据并且保存到不同的sheet工作表
writer = pd.ExcelWriter('path1',mode='w')
for col in column:
sheet = table.filter(like=col ,axis=0)
pd.DataFrame(sheet).to_excel(writer,sheet_name=col,index=False)
4.保存文件并关闭
writer.save()
writer.close()
5.完整代码
import pandas as pd
table = pd.read_excel('path0',sheet_name='sheetName')
columns= table ['列名称'].values
table ['indexs'] = columns
table .set_index('indexs',inplace=True)
column= set(columns)
writer = pd.ExcelWriter('path1',mode='w')
for col in column:
sheet = table.filter(like=col ,axis=0)
pd.DataFrame(sheet).to_excel(writer,sheet_name=col,index=False)
writer.save()
writer.close()