Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XlsxWriter error for percent format

I'm using Pandas and exporting data to excel using XlsxWriter. One of the data columns has floats and needs to be formatted as percent, so this is how I do it:

percent_fmt = workbook.add_format({'num_format': '0.00%'})
worksheet.set_column('E:E', percent_fmt)

After that the following error appears:

File "C:\Program Files\Anaconda\lib\site-packages\xlsxwriter\worksheet.py", line 4688, in _write_col_info / float(max_digit_width) * 256.0) / 256.0

TypeError: unsupported operand type(s) for *: 'Format' and 'int'

What am I doing wrong here?

like image 943
Gabriel Avatar asked Oct 06 '15 18:10

Gabriel


People also ask

How do you conditional format in Excel using Python?

Practical Data Science using Python Excel uses conditional formatting to change the appearance of cells in a range based on user defined criteria. From the conditional formatting menu, it is possible to define criteria involving various types of values. In the worksheet shown below, the column A has different numbers.

What is Xlsxwriter in Python?

XlsxWriter is a Python module for writing files in the XLSX file format. It can be used to write text, numbers, and formulas to multiple worksheets. Also, it supports features such as formatting, images, charts, page setup, auto filters, conditional formatting and many others.


1 Answers

You need to specify a width before the format or None if you don't want to adjust the width.

worksheet.set_column('E:E', None, percent_fmt)
like image 94
jmcnamara Avatar answered Oct 21 '22 01:10

jmcnamara