徐伟
[转载]python 合并多个EXCEL文件
2021-11-8 18:52
阅读:2115



#python 3.10.0 合并excel文件到一个文件

import pandas as pd

import os

import warnings


warnings.filterwarnings("ignore")

file_dir=input("请输入表格文件所在文件夹:")

filedir=input("请输入合并后文件所在文件夹:")

filename=input("请输入合并后的完整文件名(包含扩展名):")

new_filename=filedir+"\\"+filename

file_list=os.listdir(file_dir)

new_list=[]


for file in file_list:

    file_path=os.path.join(file_dir,file)

    dataframe=pd.read_excel(file_path)

    new_list.append(dataframe)


print("合并后的文件{}".format(new_filename))


result=pd.concat(new_list)

result.head()

result.shape


result.to_excel(new_filename,index=False)


转载本文请联系原作者获取授权,同时请注明本文来自徐伟科学网博客。

链接地址:https://wap.sciencenet.cn/blog-216525-1311528.html?mobile=1

收藏

分享到:

当前推荐数:0
推荐到博客首页
网友评论0 条评论
确定删除指定的回复吗?
确定删除本博文吗?