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?
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With