openpyxl icon indicating copy to clipboard operation
openpyxl copied to clipboard

question: Problem in output big float numbers

Open breno-jesus-fernandes opened this issue 2 years ago • 0 comments

Problem in output big float numbers

I have some a weird situation trying to get the output in to_excel pandas function with openpyxl engine.

I tried to read a xlsx excel file with the number "21631706.9893399", but when a try to write in a new xlsx excel file gives me the output "21631706.98934". I tested with openpyxl and xlsxwriter but I got the same results, however if I tried to write a xls excel with xlwt engine it gives me the right answer, is there a way to read and write the same float number with these engines? I suspect there some float limitations in xlsx file, but in the xlsx input the number is fine. By the way, it is not a question about formating number, the ouput number is actually different from the original input.

My code:

import pandas as pd

df = pd.read_excel(r'input\sample.xlsx')

df.to_excel(r'output\excel xlsx - xlsxwriter.xlsx', engine='xlsxwriter', index=False)
df.to_excel(r'output\excel xlsx - openpyxl.xlsx', engine='openpyxl', index=False)
df.to_excel(r'output\excel xls - xlwt.xls', engine='xlwt', index=False)

Github Example

Dependencies:

python = "3.7.4" pandas = "1.3.5" XlsxWriter = "3.0.3" openpyxl = "3.0.9" xlwt = "1.3.0"

breno-jesus-fernandes avatar May 02 '22 09:05 breno-jesus-fernandes