pythonpandas合并多个excel(xls和xlsx)⽂件(弹窗选择⽂件夹和保
存⽂件)
# python pandas合并多个excel(xls和xlsx)⽂件(弹窗选择⽂件夹和保存⽂件)
python怎么读取xls文件import tkinter as tk
from tkinter import filedialog
import os
import pandas as pd
import glob
root = tk.Tk()
root.withdraw()
# 选择⽂件夹位置
filelocation = path(filedialog.askdirectory(wd()))
lst=[]
# 读取⽂件夹下所有⽂件(xls和xlsx都读取)
for i in glob.glob(filelocation + "\\\\" + "*.*"):
if os.path.splitext(i)[1] in [".xls", ".xlsx"]:
lst.ad_excel(i))
# 保存合并后的excel⽂件
writer = pd.ExcelWriter(filedialog.asksaveasfilename(title = "保存", initialdir = filelocation, defaultextension = "xlsx", filetypes = [("Excel ⼯作簿", "*.xlsx"), ("Excel 97-2003 ⼯作簿", "*.xls")])) pd.concat(lst).to_excel(writer, 'all', index=False)
writer.save()
print('\n%d个⽂件已经合并成功!'% len(lst))
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论