Rtu*_*tut 3 performance export-to-excel pandas
我有一个具有12,000行和34列的数据框。熊猫大约需要15秒才能将其写入Excel。我读到的关于to_excel函数的讨论很少,而使其更快的一种方法是添加engine ='xlsxwriter'。我使用以下代码。
writer = pd.ExcelWriter('outputfile.xlsx',engine='xlsxwriter')
res_df.to_excel(writer,sheet_name='Output_sheet')
Run Code Online (Sandbox Code Playgroud)
想知道是否有一种方法可以使用dask或任何其他库使此工作更快?
dataframe.memory_usage()给了我以下输出:
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
Run Code Online (Sandbox Code Playgroud)
谢谢!
小智 5
您可以使用pyexcelerate获得更快的速度。
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')
Run Code Online (Sandbox Code Playgroud)