Indices of df.describe(percentiles=np.linspace(...)) are mix of integers and decimal numbers (original) (raw)
Code Sample, a copy-pastable example if possible
import numpy as np import pandas as pd df = pd.DataFrame(columns=["a"], data=np.random.randint(10, size=30).reshape(-1, 1)) pct = np.linspace(0, 1, 20 + 1) desc = df.describe(percentiles=pct)
print(desc.index) print(desc.loc['25%']) print(desc.loc['30%'])
Problem description
If desc.index is printed out, some percentile indexes are written as decimal numbers (e.g. 30.0%, 55.0%, 85.0%), while others are whole numbers (e.g. 35%, 70%, 100%). Printing percentiles of distribution therefore requires hardcoding some decimal numbers, e.g.
print(desc.loc['0%']) print(desc.loc['5%']) print(desc.loc['10%']) print(desc.loc['15.0%']) print(desc.loc['20%']) print(desc.loc['25%']) print(desc.loc['30.0%']) print(desc.loc['35%']) print(desc.loc['40%']) print(desc.loc['45%']) print(desc.loc['50%']) print(desc.loc['55.0%']) print(desc.loc['60.0%']) print(desc.loc['65%']) print(desc.loc['70%']) print(desc.loc['75%']) print(desc.loc['80%']) print(desc.loc['85.0%']) print(desc.loc['90%']) print(desc.loc['95%']) print(desc.loc['100%'])
Expected Output
Indexes of percentiles should be either all whole numbers or either all decimal numbers.
Output of pd.show_versions()
DetailsINSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 4.15.0-50-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8
pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.16.3
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.5.0
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 0.7.3
lxml.etree: 3.5.0
bs4: 4.4.1
html5lib: 0.999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None