码迷,mamicode.com
首页 > 编程语言 > 详细

【python】合并表格

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

标签:frame   bsp   pat   pre   ram   contact   new   number   ati   

本代码兼顾了合并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】合并表格

标签:frame   bsp   pat   pre   ram   contact   new   number   ati   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!