没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
主要介绍了使用python将多个excel文件合并到同一个文件的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![xlsm](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/release/download_crawler_static/12861854/bg1.jpg)
使用使用python将多个将多个excel文件合并到同一个文件的方法文件合并到同一个文件的方法
主要介绍了使用python将多个excel文件合并到同一个文件的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工
作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
应用场景:使用pandas把多个相同结构的Excel文件合并为一个。
原始数据:
相关代码:
import os
import pandas as pd
# 将文件读取出来放一个列表里面
pwd = 'test' # 获取文件目录
# 新建列表,存放文件名
file_list = []
# 新建列表存放每个文件数据(依次读取多个相同结构的Excel文件并创建DataFrame)
dfs = []
for root,dirs,files in os.walk(pwd): # 第一个为起始路径,第二个为起始路径下的文件夹,第三个是起始路径下的文件。
for file in files:
file_path = os.path.join(root, file)
file_list.append(file_path) # 使用os.path.join(dirpath, name)得到全路径
df = pd.read_excel(file_path) # 将excel转换成DataFrame
dfs.append(df)
# 将多个DataFrame合并为一个
df = pd.concat(dfs)
# 写入excel文件,不包含索引数据
df.to_excel('test\result.xls', index=False)
合并结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- weixin_401421622024-05-15总算找到了自己想要的资源,对自己的启发很大,感谢分享~
- kefuxiaobai2024-01-31内容与描述一致,超赞的资源,值得借鉴的内容很多,支持!
- 2301_762071162024-01-29资源很好用,有较大的参考价值,资源不错,支持一下。
- 2201_756415022022-12-11资源很受用,资源主总结的很全面,内容与描述一致,解决了我当下的问题。
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
weixin_38738783
- 粉丝: 5
- 资源: 903
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)