python 合并多张表头相同的excel sheet(全网最简洁代码)

#导入要用的包

import pandas as pd

import numpy as np

import os, shutil

#开始合并

excel_path =r"E:\data"     #文件夹路径

excel_name = r"销售明细.xlsx"      #Excel名

excel_cols = ['姓名', '人数', '销量', '单价', '总销售额']         #每个sheet的表头

excel_file_name = os.path.join(agent_path, agent_name)

excel_file = pd.ExcelFile(agetn_file_name)

pd.concat([pd.read_excel(excel_file,

                        sheet_name= name,

                        names= agent_cols)

          for name in excel_file.sheet_names],

          ignore_index= True).to_csv(excel_path+ r'\excel_combine.csv', index = False, encoding = 'gbk')

你可能感兴趣的:(python 合并多张表头相同的excel sheet(全网最简洁代码))