当前位置: 首页 > article >正文

Excel大文件拆分

在这里插入图片描述

import pandas as pd

def split_excel_file(input_file, output_prefix, num_parts=10):
    # 读取Excel文件
    df = pd.read_excel(input_file)

    # 计算每部分的行数
    total_rows = len(df)
    rows_per_part = total_rows // num_parts
    remaining_rows = total_rows % num_parts

    start_row = 0
    for i in range(num_parts):
        # 计算当前部分的结束行数
        end_row = start_row + rows_per_part + (1 if i < remaining_rows else 0)
        
        # 获取当前部分的数据
        part_df = df.iloc[start_row:end_row]
        
        # 构造输出文件名
        output_file = f"{output_prefix}_part_{i+1}.xlsx"
        
        # 保存当前部分到新的Excel文件,确保表头每次都会出现
        part_df.to_excel(output_file, index=False, header=True)
        print(f"Part {i+1} saved to {output_file}")
        
        # 更新起始行号
        start_row = end_row

# 使用示例
input_file = './output_file.xlsx'  # 输入文件路径
output_prefix = 'file_split'  # 输出文件前缀

split_excel_file(input_file, output_prefix)


http://www.kler.cn/a/570388.html

相关文章:

  • 【网络原理】详解 HTTPS 协议
  • Python - Python操作Redis
  • 简单的前端原型:个性化广告文案生成
  • 从零开始构建高效Spring Boot应用:实战案例与最佳实践
  • vue3+ts+uniapp+unibest 微信小程序(第四篇)——小程序分包,解决主包过大无法上传平台问题
  • 深度学习transfomer架构的职业匹配系统
  • iOS开发之最新Demo上传Github步骤(2025.02.28)
  • 虚拟机配置
  • HTTP四次挥手是什么?
  • 编辑器的使用
  • 【Python】使用库
  • 可视化的决策过程:决策树 Decision Tree
  • 【django】模型部署过程
  • linux(rocky)设置更新服务器时间
  • 开源操作系统纷争:CentOS停服后的新战场
  • 【PromptCoder + Cursor】利用AI智能编辑器快速实现设计稿
  • 爬虫结合 t_nlp_word 文本语言词法分析接口:开启数据挖掘与分析的新篇章
  • VTK知识学习(44)- 表面重建
  • miqiu的分布式锁(四):MySQL悲观锁解析
  • Go的基本语法学习与练习