# -*- coding:utf-8 -*- #将多个Excel文件合并成一个 import pandas as pd if __name__=='__main__': #定义要合并的excel文件列表 part1 = u'新标签数据监测_' part2 = u'atx.xlsx' allxls=[part1 + '0617'+part2,part1 + '0618'+part2] all_file = part1 + '0616' + part2 #存储所有读取的结果 for add_file in allxls: main_data = pd.ExcelFile(all_file) main_sheets = main_data.sheet_names add_data = pd.ExcelFile(add_file) add_sheets = main_data.sheet_names # 合并两个文件的所有sheet表 all_data = pd.ExcelWriter(all_file) # sheet = main_sheets[0] for sheet in main_sheets: main1 = pd.read_excel(all_file, sheet_name=sheet) add1 = pd.read_excel(add_file, sheet_name=sheet) all1 = pd.concat([add1, main1], axis=0) all1.to_excel(all_data, sheet) print u'完成表' + sheet all_data.save()