Skip to content

Pandas style.set_precision not working as expected #13257

Closed
@Peter9192

Description

@Peter9192

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO HTMLread_html, to_html, Styler.apply, Styler.applymapOutput-Formatting__repr__ of pandas objects, to_stringgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions