有没有办法不在熊猫中显示数字值的科学符号?

发布于 2025-02-06 02:59:25 字数 705 浏览 2 评论 0原文

我询问了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生殊途 2025-02-13 02:59:28

不可能禁用熊猫中的科学符号。但是,有几种方法可以解决此问题:

使用.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文