多个excel合并

目的:将同一个文件下的多个 "京东差评.xlsx" 合并为一个:"京东汇总.xlsx"

代码如下:

复制代码
# -*- coding: utf-8 -*-
"""
Created on Wed Oct  4 12:52:32 2023

@author: 64884
"""

import pandas as pd
import os
data_list = []

# os.listdir(".")返回目录中的文件名列表
# 用for循环遍历文件名列表中的每个文件名,赋值给变量filename
for filename in os.listdir("C:\博士选题\数据搜集"):
    # 判断文件名是否以"销售表-"开头并且以".xlsx"结尾
    if filename.startswith("京东差评") and filename.endswith(".xlsx"):
        data_list.append(pd.read_excel(filename))

# concat合并Pandas数据
data_all =pd.concat(data_list)
# 将 DataFrame 保存为 excel 文件
data_all.to_excel("京东差评汇总.xlsx",index=False)

效果:

相关推荐
jaysee-sjc10 小时前
【苍穹外卖】Day12:工作台数据看板与 Excel 报表导出
java·开发语言·数据库·spring boot·spring·微信·excel
ms365copilot14 小时前
Copilot 代理开始进入Word、Excel、PowerPoint,不再只是“问一句答一句”
word·excel·copilot
wuyk55515 小时前
PyQt6-第14讲-数据库与Excel双向同步
数据库·python·ui·excel·pyqt
qq_3646821516 小时前
AI如何将录音内容自动整理成Excel清单
人工智能·excel
Logic10117 小时前
Excel信息+照片文件夹,自动合成word格式化文档
word·excel·办公自动化·邮件合并·office技巧·自动插入图片·插入域
Data-Miner2 天前
一个省大模型积分的 Excel 数据处理方案:脱敏生成逻辑,脚本复用把 token 降到 0
人工智能·windows·excel
Logic1012 天前
表格智能记账3 销售与库存智能联动,自动标红库存预警
excel·条件格式·excel技巧·vlookup·sumif
技术小甜甜3 天前
【Copilot】能选 Claude 和 GPT-6 了,Excel 分析该交给谁
gpt·excel·copilot·claude·microsoft365·gpt-6
小白今天也很酷4 天前
MCXN947更新板载DAP_Link固件的方法
c语言·python·单片机·ubuntu·excel·1024程序员节
ratel️5 天前
小墨析 · Office Agent 日常办公不烧心
python·langchain·word·excel·fastapi·js·ppt