Skip to content

Pandas style.set_precision not working as expected #13257

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
Peter9192 opened this issue May 23, 2016 · 2 comments · Fixed by #27934
Closed

Pandas style.set_precision not working as expected #13257

Peter9192 opened this issue May 23, 2016 · 2 comments · Fixed by #27934
Labels
good first issue IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@Peter9192
Copy link

Peter9192 commented May 23, 2016

I expected the following code to give me a representation of my data that is rounded or truncated to 2 decimals.

import pandas as pd
import numpy as np

df = pd.DataFrame(data = np.random.randn(4,4), columns=['A','B','C','D'])
df.style.set_precision(2)

However, it will always return 2 digits instead, so for example, I want 2.37419 to be displayed as 2.37, but instead this code will give me 2.4. Am I overseeing something or is this a bug?

Note that the following code works as I expected, but then I change a general setting whereas I would like to apply it only to the current output:

pd.set_option('display.precision',2)
df

I'm using pandas version 0.18.1 in Jupyter notebook on Firefox, with python 2.7.11.final.0 and IPython 4.1.2 on 64-bits linux.

@TomAugspurger TomAugspurger added Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap labels May 23, 2016
@TomAugspurger TomAugspurger added this to the 0.18.2 milestone May 23, 2016
@TomAugspurger
Copy link
Contributor

I believe this is just reusing something like this from python

>>> '{:.2g}'.format(2.37419)
'2.4'

Would take a PR fixing this to have the 2.37 like expected. I think we recently fixed a similar problem with the 'display.precision' option.

@ruchigarg-DS
Copy link

df = pd.DataFrame([123.4567, 234.5678, 345.6789, 456.7890],
index=['a','b','c','d'],
columns=['cost'])
df.style.set_precision(precision=2)

  cost
1.2e+02
2.3e+02
3.5e+02
4.6e+02
  cost
1.2e+02
2.3e+02
3.5e+02
4.6e+02

AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 15, 2019
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 19, 2019
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 19, 2019
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 19, 2019
BUG: set_precision format fixed (pandas-dev#13257)

fix

fix pep8
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 19, 2019
BUG: set_precision format fixed (pandas-dev#13257)

fix

fix pep8

fix pep8
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 19, 2019
BUG: set_precision format fixed (pandas-dev#13257)

fix

fix pep8

fix pep8

black pandas
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 20, 2019
BUG: set_precision format fixed (pandas-dev#13257)

fix

fix pep8

fix pep8

black pandas

whatsnew
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 20, 2019
BUG: set_precision format fixed (pandas-dev#13257)

fix

fix pep8

fix pep8

black pandas

whatsnew

fix small
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 21, 2019
BUG: set_precision format fixed (pandas-dev#13257)

fix

fix pep8

fix pep8

black pandas

whatsnew

fix small

fix small
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 21, 2019
BUG: set_precision format fixed (pandas-dev#13257)

fix

fix pep8

fix pep8

black pandas

whatsnew

fix small

fix small

fix small
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 22, 2019
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Aug 23, 2019
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Sep 3, 2019
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Sep 19, 2019
Co-Authored-By: Tom Augspurger <[email protected]>

conflit whatsnew
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Sep 19, 2019
Co-Authored-By: Tom Augspurger <[email protected]>

conflit whatsnew

conflit whatsnew
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Sep 19, 2019
Co-Authored-By: Tom Augspurger <[email protected]>

conflit whatsnew

conflit whatsnew

testes
AntonioAndraues pushed a commit to AntonioAndraues/pandas that referenced this issue Oct 15, 2019
@jreback jreback modified the milestones: Contributions Welcome, 1.0 Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
6 participants