python合并目录下多个excel的xlsx文件到一个excel中

发布于 2020-03-18 22:41:40

将文件夹中xlsx文件合并到一个excel文件中


import xlrd
import os
import pandas as pd
import glob 
from numpy import *
import  pandas as pd
location = 'C:/Users/CQ375/Desktop/ex'
fileList = []
n=0
for fileName in os.walk(location):
    for table in fileName[2]:
        path = fileName[0] + '/' + table 
        Li=pd.read_excel(path,header=0)
        n = n+1 
        fileList.append(Li)
        print('第' + str(n) + '个表格已合并')
print("在该目录下有%d个xlsx文件"%len(fileList))
data_result = pd.concat(fileList,ignore_index=True)
data_result.to_excel('C:/Users/CQ375/Desktop/ex/test.xlsx',index=0)
0 条评论

发布
问题