gpt4 book ai didi

python - 如何更改 html 输出的数字数据格式

转载 作者:太空狗 更新时间:2023-10-29 21:45:15 25 4
gpt4 key购买 nike

我有生成 Pandas 数据框并以 html 格式发送电子邮件的代码。
我遇到的问题是很难将数字的科学格式更改为通用样式

我已经尝试设置 float 格式,但没有成功。

pd.options.display.float_format = '{:20,.2f}'.format

输出:

Col A        Col B
1.00E+06 2.28E+06
3.00E+07 -2.54E+07

预期输出:

Col A        Col B
1000420 2281190
30030200 -25383100

最佳答案

我试过了,它成功了:

df = pd.DataFrame([[3.371e17,9.82173e15],[8e12,8e8]],columns=['A','B'])

df.to_html(float_format='{:20,.2f}'.format)

一般来说,这并没有改变 df 的格式,只是改变了 html 输出,即:

<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>A</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>337,100,000,000,000,000.00</td>
<td>9,821,730,000,000,000.00</td>
</tr>
<tr>
<th>1</th>
<td>8,000,000,000,000.00</td>
<td>800,000,000.00</td>
</tr>
</tbody>
</table>

关于python - 如何更改 html 输出的数字数据格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46180786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com