【python】合并表格
本代码兼顾了合并sheet与合并表格的功能
import os import pandas as pddef 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)
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16