有没有办法不在熊猫中显示数字值的科学符号?
我询问了Postgres数据库以从表中检索信息:
SQLResults = cursor.execute('SELECT x.some_12_long_integer from test as x;')
当我在数据库中运行此查询时,我会得到1272140958198
,但是当我将其转储到dataframe中时:
现在, 代码>是INT8。
我正在使用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)
将其转换为Excel时,它会产生1.27214E+12
,但是当我在Excel文件中格式化时,我会得到1272140958198
。
我该如何将其保留为1272140958198
而不是1.27214e+12
?
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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可能禁用熊猫中的科学符号。但是,有几种方法可以解决此问题:
使用.to_string()将数字值转换为字符串。这将删除科学符号,并提供对数据的用户友好表示。在数字值上执行数学操作,以便将它们舍入特定数量的小数位。这将消除大多数科学符号,但有些仍可能保留。
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.