0

I queried my postgres database to retrieve information from a table:

SQLResults = cursor.execute('SELECT x.some_12_long_integer from test as x;')

Now when I run this query in database, I get 1272140958198, but when I dump this in a dataframe:

The x.some_12_long_integer is int8.

I am using xlsxwriter:

excel_writer =  ExcelWriter(
    self.fullFilePath, engine="xlsxwriter",
    engine_kwargs={'options': {'strings_to_numbers': True}}
)

frame = DataFrame(SQLResults[0])
frame.to_excel(excel_writer, sheet_name="Sheet1", index=False)

When it is converted to Excel it produces 1.27214E+12 but when I format the cell in the Excel file I get 1272140958198.

How can I make it just stay as 1272140958198 instead of 1.27214E+12?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Fehr Faber
  • 35
  • 6

1 Answers1

0

It is not possible to disable scientific notation in pandas. However, there are a few ways to work around this:

Convert the numeric values to strings using .to_string() . This will remove the scientific notation and provide a more user-friendly representation of the data. Perform mathematical operations on the numeric values in order to round them off to a specific number of decimal places. This will remove most of the scientific notation, but some may still remain.