BUG: Calling to_html with float_format strips all trailing zeros if an integer string is returned from the formatter · Issue #40024 · pandas-dev/pandas (original) (raw)


Code Sample, a copy-pastable example

import pandas as pd df = pd.DataFrame(data={'x': [1000.0, 'test']}) # Column dtype must be object df.to_html(float_format=lambda x: '{:,.0f}'.format(x))

Output:

'

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
x
01,
1test
'

Problem description

This caused by the rstrip in pandas.io.formats.format._trim_zeros_single_float()

Expected Output

'

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
x
01,000
1test
'

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
pandas           : 1.2.2
numpy            : 1.20.1
pytz             : 2021.1
dateutil         : 2.8.1
pip              : 20.3.3
setuptools       : 51.3.3