临时想要合并一些excel文件,发现用pandas还挺方便。但觉得速度有些慢,可以改进。先这样吧,:-D。
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 30 12:13:53 2018
@author: Ye
"""
import pandas as pd
from os import walk
# 利用walk函数取得文件名,并判断是否为xlsx文件
files = []
for f, _, i in walk('#目录地址'):
for j in i:
if j.split('.')[1] == 'xlsx':
files.append(j)
to_list = []
for file in files:
to_list.append(pd.read_excel(file))
write = pd.ExcelWriter('combi.xlsx')
pd.concat(to_list).to_excel(write, 'Sheet1', index=False)
write.save()