Skip to content

Strange behaviour of the precision display option #20359

Closed
@dexter2206

Description

@dexter2206

Consider the following example:

import pandas as pd
s = pd.Series([840.0, 4200.0])
pd.set_option('precision', 0)
print(s)
pd.set_option('precision',2)
print(s)

The first print produces 84, 420, while the second one produces correctly 840.0 and 4200.0.

Problem description

If I understand docs correctly, the precision option should affect only the number of digits after the decimal point, not the digits before it.

Expected Output

First print shows 840 and 4200 (or 840.0, 4200.0).

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.8-300.fc27.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: pl_PL.UTF-8
LOCALE: pl_PL.UTF-8

pandas: 0.22.0
pytest: 3.3.1
pip: 9.0.1
setuptools: 36.5.0
Cython: None
numpy: 1.14.2
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: 0.4.1
dateutil: 2.7.0
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.2
openpyxl: 2.4.9
xlrd: 1.0.0
xlwt: None
xlsxwriter: 1.0.2
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions