python - 使用 pandas 将文件连接成 2 个数据帧
问题描述
我有一个包含 4 个文件的文件夹,我想将 2 个第一个文件连接到 df1 并将 2 个第二个文件连接到 df2
我找到了这种方法,但实际上它将所有文件连接到一个数据框中
fiels = #the path
df= pd.concat([pd.read_excel(fiel) for fiel in glob.glob(fiels+ "/*.xlsx")],ignore_index=True)
请问有什么建议吗?
解决方案
IIUC 通过索引选择文件 - 前 2 个和所有其他文件,如:
files = glob.glob(fiels+ "/*.xlsx")
df1 = pd.concat([pd.read_excel(fiel) for fiel in files[:2]],ignore_index=True)
df2 = pd.concat([pd.read_excel(fiel) for fiel in files[2:]],ignore_index=True)
推荐阅读
- javascript - 反应页面不从顶部呈现
- wordpress - 无法使用 Elementor 编辑 Wordpress 网站(“更新失败”)
- javascript - 与 async.parallel 斗争
- oracle11g - 无法访问表空间的 Oracle 用户是否可以将值插入到放置在该表空间中的表中?
- php - 如何在laravel中存储多个关系
- python - 如何根据 python 中的用户输入检查从数组中随机生成的值?
- node.js - 为什么 .pre find 查询在这种情况下返回 undefined?
- r - 对列字符串的唯一组合进行子集化
- php - php - 从逗号分隔的值范围中获取最小值和最大值
- shopify - Complete Checkout API 给出错误“无法在没有任何交易的情况下完成结帐 shopify”