Skip to content

to_html local float_format decimal representation #12445

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

Closed
ghost opened this issue Feb 25, 2016 · 3 comments
Closed

to_html local float_format decimal representation #12445

ghost opened this issue Feb 25, 2016 · 3 comments
Labels
IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string Usage Question

Comments

@ghost
Copy link

ghost commented Feb 25, 2016

Hello,

Because of the decimal symbol I'm forced to use the following code. The problem is when the using is "big", for example: 1 356 747 -> 1,35675e+06. Is there any work around?

import locale
loc = locale.getlocale() # get current locale
locale.setlocale(locale.LC_NUMERIC, "Portuguese_Portugal")
html_table = df.to_html(header=True, index=False, na_rep="", float_format="{:n}".format, justify="center")
locale.setlocale(locale.LC_NUMERIC, loc) # restore saved locale
print(html_table)

Code Sample, a copy-pastable example if possible

AMOUNT 1,35675e+06 95 524 179 347 255 691 #### Expected Output AMOUNT 1 356 747 95 524 179 347 255 691 #### output of `pd.show_versions()` ## INSTALLED VERSIONS

commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Windows
OS-release: 2012ServerR2
machine: AMD64
processor: Intel64 Family 6 Model 47 Stepping 2, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.17.1
nose: None
pip: 8.0.2
setuptools: 20.1.1
Cython: None
numpy: 1.10.4
scipy: 0.17.0
statsmodels: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: None
xlsxwriter: 0.8.4
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
Jinja2: None
None

@jreback jreback added Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap labels Feb 25, 2016
@jreback
Copy link
Contributor

jreback commented Feb 25, 2016

this was recently merged: #12417

and will be available in forthcoming 0.18.0 (its not in 0.18.0rc1).

this adds the decimal parameter which I think should work.

cc @nbonnotte

@nbonnotte
Copy link
Contributor

Yes, df.to_html(decimal=',') should work in 0.18.0.

Until then, a workaround could be for instance df.to_html(float_format=lambda x: '{:n}'.format(x).replace('.', ',', 1)).

@ghost
Copy link
Author

ghost commented Feb 25, 2016

Thank you very much for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string Usage Question
Projects
None yet
Development

No branches or pull requests

2 participants