Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas create zip file from ExcelWriter

Tags:

python

pandas

I'm getting the error File Size would require Zip64 when running the following code. The excel conversion is to large to save to disk to be later converted. Is there a way to zip before saving to disk? I tried writer.book.use_zip64() but it will not work. The result of the output from to_excel function is NoneType if assign it to a variable.

    writer = pd.ExcelWriter(file_name,engine='xlsxwriter')
    output_df.round(2)
    output_df.to_excel (writer, index = False, header=True)
    writer.save()
like image 522
r lo Avatar asked Apr 17 '20 19:04

r lo


People also ask

How does pandas write Excel files?

Pandas writes Excel files using the Xlwt module for xls files and the Openpyxl or XlsxWriter modules for xlsx files. To use XlsxWriter with Pandas you specify it as the Excel writer engine:

How to apply xlsxwriter features to pandas output?

In order to apply XlsxWriter features such as Charts, Conditional Formatting and Column Formatting to the Pandas output we need to access the underlying workbook and worksheet objects. After that we can treat them as normal XlsxWriter objects.

How to export Dataframe from pandas Dataframe to excel?

) You can see that there are three sheets, and each sheet has different Name columns. The to_excel () function accepts sheet_name as a parameter, and here we can pass the three different sheet names and that DataFrame is saved in the respective sheets. If you want to export Pandas DataFrame to Excel files, then ExcelWriter () class is all you need.

How to create an Excel file in Python?

Excel files can be created in Python using the module Pandas. In this article we will show how to create an excel file using Python. We start by importing the module pandas. From the module we import ExcelWriter and ExcelFile. The next step is to create a data frame.


1 Answers

I tried writer.book.use_zip64() but it will not work.

It should work. Here is a working example based on your snippet:

import pandas as pd

output_df = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]})

file_name ='pandas_simple.xlsx'

writer = pd.ExcelWriter(file_name, engine='xlsxwriter')
output_df.round(2)
output_df.to_excel(writer, index = False, header=True )

writer.book.use_zip64()

writer.save()

like image 113
jmcnamara Avatar answered Oct 20 '22 11:10

jmcnamara