挑选出行数足够的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)
相关推荐
花酒锄作田13 小时前
Pydantic校验配置文件
python
hboot13 小时前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi1 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi1 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽1 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187911 天前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L2 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅2 天前
海天线算法的前世今生
python·计算机视觉
韩师傅2 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L2 天前
LangGraph的MessageState and HumanMessage
python