我有一个包含 12,000 行和 34 列的数据框。 pandas 将其写入 Excel 大约需要 15 秒。我读到了一些关于 to_excel 函数的讨论,使其更快的一种方法是添加 engine='xlsxwriter'。我使用以下代码。
writer = pd.ExcelWriter('outputfile.xlsx',engine='xlsxwriter')
res_df.to_excel(writer,sheet_name='Output_sheet')
想知道是否有办法使用 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
Thanks!
您可以使用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')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)