挑选出行数足够的excel文件

**

遍历文件夹下的所有excel文件,并将数据量超过指定标准的文件拷贝到指定文件夹中

python 复制代码
import os.path
import shutil
import pandas as pd


def copy_excel_files(source_folder, target_folder, row_threshold):
    if not os.path.exists(target_folder):
         os.makedirs(target_folder)

    for filename in os.listdir(source_folder):
        if filename.endswith(
                ('.xlsx', '.xls')
        ):
            file_path = os.path.join(source_folder, filename)
            try:
                df = pd.read_excel(file_path)
                if len(df) > row_threshold:
                    target_path = os.path.join(target_folder, filename)
                    shutil.copy2(file_path, target_path)
                    print(f"已复制文件{filename}")
            except Exception as e:
                print(f"处理文件{filename}时出错:{e}")

if __name__ == "__main__":
    # 源文件夹路径
    source_folder = '自定义路径1'
    # 目标文件夹路径
    target_folder = '自定义路径2'
    # 行数阈值,可根据需要修改
    row_threshold = 50

    copy_excel_files(source_folder, target_folder, row_threshold)
相关推荐
2601_962299241 小时前
Azure python操作系统列表
python·操作系统·azure·虚拟机·存储配置文件
2601_962071572 小时前
【Java报错已解决】org.springframework.beans.factory.BeanCreationException
java·开发语言
学术 学术 Fun2 小时前
如何用 API 与 Webhook 批量把图表图片转换成 VSDX
python·自动化·api·visio
淡海水3 小时前
07-04-并发-ConcurrentBag-T-工作窃取WorkStealing算法
开发语言·算法·c#·bag·concurrent·workstealing
2601_962100543 小时前
python包和模块的内容整理
python·模块·导入·虚拟环境·
CS_Zero3 小时前
C语言sizeof是函数吗?
c语言·开发语言
二进制漫游记3 小时前
FastAPI项目集成 Qdrant向量数据库+阿里云Embedding完整实战(工具封装+业务调用)
数据库·python·阿里云·embedding
-今昭-4 小时前
《V2V 迁移实战:将 VMware 虚拟机转为 OpenStack 可用 Glance qcow2 镜像》
开发语言·python
2601_962381584 小时前
【转】Python渗透测试工具:sqlmap
python·渗透测试·sql注入·sqlmap·数据库安全
用户3721574261355 小时前
如何使用 Python 从 Word 文档中提取图片
python