Pandas to_html float_format

时间:2015-12-22 00:21:27

标签: python pandas format

我有以下数据框:

CLIENT | AMOUNT
N130   | 1000.50

并希望将其插入电子邮件中。

var = df.to_html(header=True, index=False, na_rep="", float_format="{:,}".format)

问题是数量的格式为1,000.50,我假装的是1.000,50。

我还尝试使用.apply格式化AMOUNT列,但没有成功。有人可以帮我解决这个问题。提前谢谢。

1 个答案:

答案 0 :(得分:3)

您需要设置locale

import locale
locale.setlocale(locale.LC_ALL, '')

并使用以下格式的n

df.to_html(header=True, index=False, na_rep="", float_format="{:n}".format)

如果这不会产生所需的结果,请更改为其他locale

locale.setlocale(locale.LC_ALL, it_IT.UTF-8')
相关问题