Skip to content
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

Indices of df.describe(percentiles=np.linspace(...)) are mix of integers and decimal numbers #26660

Closed
jkovacevic opened this issue Jun 5, 2019 · 2 comments

Comments

@jkovacevic
Copy link
Contributor

commented Jun 5, 2019

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()

INSTALLED 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

@WillAyd

This comment has been minimized.

Copy link
Member

commented Jun 5, 2019

Makes sense. If you'd like to take a look would certainly welcome a PR

@WillAyd WillAyd added the Numeric label Jun 5, 2019

@WillAyd WillAyd added this to the Contributions Welcome milestone Jun 5, 2019

@jkovacevic

This comment has been minimized.

Copy link
Contributor Author

commented Jun 5, 2019

Would by my pleasure. I will follow up on this over this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.