如何将包含+1.048.576行的一个数据框导出到多个Excel文件/表格 [英] How to export one dataframe, which contains +1.048.576 rows, into multiple excel files/sheets

查看:42
本文介绍了如何将包含+1.048.576行的一个数据框导出到多个Excel文件/表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算导入多个Excel文件,并使用append方法来获取包含我需要的所有信息的数据框.但是,我确定数据框中的行数将超过excel的行数限制.因此,在导出数据时,必须将数据进行划分并存储在多个Excel工作表中,或更优选地,将其存储在文件中.我该怎么做?

I'm planning to import multiple excel files and use append method to obtain a dataframe that contains all of the information I need. However, I am certain that the number of rows in the dataframe will exceed the row limit of excel. Therefore, while exporting the data must be divided and stored in multiple excel sheets or, more preferably, files. How can I perform that?

推荐答案

您可以在打印到文件时在for循环中进行操作.示例代码:

You can do it in for loop while printing out to file. Sample code:

number_of_row = 60000

loop_count = int(len(df) / number_of_row)

for cycle in range(loop_count):
    df[cycle*number_of_row:(cycle+1)*number_of_row].to_excel('part-{}.xls'.format(cycle))

这篇关于如何将包含+1.048.576行的一个数据框导出到多个Excel文件/表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆