Rivers分享 http://blog.sciencenet.cn/u/sdssxwfd

博文

[转载]python 合并多个EXCEL文件

已有 2119 次阅读 2021-11-8 18:52 |个人分类:未分类|系统分类:教学心得|文章来源:转载



#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://blog.sciencenet.cn/blog-216525-1311528.html

上一篇:熵权法的Matlab实现
下一篇:元胞自动机之退火规则
收藏 IP: 121.250.0.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-20 16:06

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部