首页 > 编程语言 > 详细

【python】合并表格

时间:2020-02-11 12:55:17      阅读:75      评论:0      收藏:0      [点我收藏+]

本代码兼顾了合并sheet与合并表格的功能

import os
import pandas as pd
def combine_sheet(excel_path, number): #excel_path is str and num is the sequence number of the excel excel = pd.read_excel(excel_path, sheet_name = None, header = None) keys = list(excel.keys()) excel_contact = pd.DataFrame() for i in keys: excel_sheet = excel[i] excel_contact = pd.concat([excel_contact, excel_sheet]) excel_contact.to_excel(vocabulary{}.xlsx.format(number), header= False, index=None) def combine_excel(excels_path): #excel_path is a list of excel files‘ name excel_combination = [] for i in excels_path: excel_combination.append(pd.read_excel(i, header=None)) new_excel = pd.concat(excel_combination) new_excel.to_excel(vocabulary.xlsx, header = False, index=None) os.chdir(C:\\Users\\11440\\OneDrive) combine_sheet(词汇.xlsx, 1) combine_sheet(词汇2.xlsx, 2) excel_list = ["vocabulary1.xlsx", "vocabulary2.xlsx"] combine_excel(excel_list)

 

【python】合并表格

原文:https://www.cnblogs.com/PKU-CD/p/12294164.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!