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)
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of pandas.
- (optional) I have confirmed this bug exists on the master branch of pandas.
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 | x | \n
---|---|
0 | \n1, | \n
1 | \ntest | \n
Problem description
This caused by the rstrip in pandas.io.formats.format._trim_zeros_single_float()
Expected Output
'
\n | x | \n
---|---|
0 | \n1,000 | \n
1 | \ntest | \n
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