本文介绍了 pandas to_excel-如何使其更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含12,000行和34列的数据框.熊猫大约需要15秒才能将此内容写入Excel.我读到的关于to_excel函数的讨论很少,而使其更快的一种方法是添加engine ='xlsxwriter'.我使用以下代码.
I have a dataframe with 12,000 rows and 34 columns. It takes around 15 sec for pandas to write this to the excel. I read few discussion about to_excel function and one way to make it faster is by adding engine='xlsxwriter'. I use the following code.
writer = pd.ExcelWriter('outputfile.xlsx',engine='xlsxwriter')
res_df.to_excel(writer,sheet_name='Output_sheet')
想知道是否有一种方法可以使用dask或其他任何库来使这项工作更快?
Wondering if there is a way to make this work faster using dask or any other library?
dataframe.memory_usage()给了我以下输出:
dataframe.memory_usage() gave me the following output:
Index 80
col1 95528
col2 95528
col3 95528
col4 95528
col5 95528
col6 95528
col7 95528
col8 95528
col9 95528
col10 95528
col11 95528
col12 95528
col13 95528
col14 95528
col15 95528
col16 95528
col17 95528
col18 95528
col19 95528
col20 95528
col21 95528
col22 95528
col23 95528
col24 95528
col25 95528
col26 95528
col27 95528
col28 95528
col29 95528
col30 95528
col31 95528
col32 95528
col33 95528
col34 95528
谢谢!
推荐答案
您可以使用 pyexcelerate 来获取更快的速度.
You can use pyexcelerate to get a much faster speed.
from pyexcelerate import Workbook
values = [res_df.columns] + list(res_df.values)
wb = Workbook()
wb.new_sheet('sheet name', data=values)
wb.save('outputfile.xlsx')
这篇关于 pandas to_excel-如何使其更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!