Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas to_html float_format

I've the following dataframe:

CLIENT | AMOUNT
N130   | 1000.50

And want to insert it into an email.

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

The problem is that the amount has the format 1,000.50 and what I pretend is the exact opposite 1.000,50.

I've also tried to format the column AMOUNT using .apply but with no success. Can someone help me with this problem. Thanks in advance.

like image 392
Aghuttun Avatar asked Sep 05 '25 11:09

Aghuttun


1 Answers

You need to set the locale

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

and use the n in the format:

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

If this does not produce the desired result, change to a different locale

locale.setlocale(locale.LC_ALL, it_IT.UTF-8')
like image 188
Mike Müller Avatar answered Sep 08 '25 04:09

Mike Müller