Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_html w/ float_format="%.0f" renders 100.0 as 1 #22270

Closed
tothandor opened this issue Aug 10, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@tothandor
Copy link

commented Aug 10, 2018

Code Sample, a copy-pastable example if possible

import pandas as pd
print(pd.DataFrame([100.0]).to_html(float_format='%.0f'))

Problem description

The above code will render a value of 1 instead of 100.

<table border="1" class="dataframe">
...
      <td>1</td>
...
</table>

Expected Output

<table border="1" class="dataframe">
...
      <td>100</td>
...
</table>

Output of pd.show_versions()

INSTALLED VERSIONS [0/1850]

commit: None
python: 2.7.5.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-123.20.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.23.4
pytest: None
pip: 18.0
setuptools: 39.1.0
Cython: 0.23.4
numpy: 1.14.0
scipy: 1.0.0
pyarrow: 0.9.0
xarray: None
IPython: 5.6.0
sphinx: None
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.2
feather: 0.4.0
matplotlib: 1.4.3
openpyxl: 2.4.9
xlrd: 0.9.3
xlwt: 1.0.0
xlsxwriter: 0.9.6
lxml: 3.4.2
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.0.12
pymysql: None
psycopg2: 2.6.1 (dt dec pq3 ext)
jinja2: 2.8
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@tothandor

This comment has been minimized.

Copy link
Author

commented Aug 10, 2018

DataFrame.to_string() is also affected.
It seems that _trim_zeros causes the problem pandas/io/formats/format.py+1053:

class FloatArrayFormatter(GenericArrayFormatter):
...
    def get_result_as_array(self):
...
        def format_values_with(float_format):
...
            if self.fixed_width:                       
                return _trim_zeros(values, self.na_rep)
@tothandor

This comment has been minimized.

Copy link
Author

commented Aug 10, 2018

Changing the default value of "fixed_width" argument of GenericArrayFormatter to False solves the problem, but may cause others.

@WillAyd

This comment has been minimized.

Copy link
Member

commented Aug 10, 2018

This may be related to the discussion in #21625 and potentially solved by the PR quoted at the end of that thread.

@tomneep since you made that commit - any interest in packaging that up with tests in a PR to see if we can knock both of these issues out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.