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

BUG: The indexes of DataFrame.describe(percentiles=[0.29, 0.57, 0.58]) are incorrect #46362

Closed
3 tasks done
idanhazan opened this issue Mar 14, 2022 · 3 comments · Fixed by #48298
Closed
3 tasks done
Assignees
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@idanhazan
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

pd.DataFrame(data=[1, 2, 3], columns=['value']).describe(percentiles=[0.29, 0.57, 0.58])

 	value
count 	3.00
mean 	2.00
std 	1.00
min 	1.00
29.0% 	1.58
50% 	2.00
57.0% 	2.14
58.0% 	2.16
max 	3.00

Issue Description

The indexes ['29.0%', '57.0%', '58.0%'] should be named as ['29%', '57%', '58%'].

Expected Behavior

pd.DataFrame(data=[1, 2, 3], columns=['value']).describe(percentiles=[0.29, 0.57, 0.58]).index

# Output:
Index(['count', 'mean', 'std', 'min', '29.0%', '50%', '57.0%', '58.0%', 'max'], dtype='object')

# Expected:
Index(['count', 'mean', 'std', 'min', '29%', '50%', '57%', '58%', 'max'], dtype='object')

Installed Versions

INSTALLED VERSIONS

commit : 06d2301
python : 3.9.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.13.0-30-generic
Version : #33-Ubuntu SMP Fri Feb 4 17:03:31 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_IL
LOCALE : en_IL.UTF-8

pandas : 1.4.1
numpy : 1.22.2
pytz : 2021.3
dateutil : 2.8.2
pip : 22.0.3
setuptools : 59.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : 4.4.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.0.3
IPython : 7.32.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : 2022.02.0
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : 2022.02.0
scipy : 1.8.0
sqlalchemy : 1.4.31
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

@idanhazan idanhazan added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 14, 2022
@idanhazan idanhazan changed the title BUG: The indexes of pandas.describe(percentiles=[0.29, 0.57, 0.58]) is incorrect BUG: The indexes of DataFrame.describe(percentiles=[0.29, 0.57, 0.58]) is incorrect Mar 14, 2022
@idanhazan idanhazan changed the title BUG: The indexes of DataFrame.describe(percentiles=[0.29, 0.57, 0.58]) is incorrect BUG: The indexes of DataFrame.describe(percentiles=[0.29, 0.57, 0.58]) are incorrect Mar 14, 2022
@ShamithaReddy
Copy link

ShamithaReddy commented Mar 15, 2022

Internally in python a number is converted from decimal to base 2 floating-point number, so any number that is not a prime factor of 2 will have numbers repeated in its binary format, and when it is precise to 53 bits we may get a number that is slightly lesser than or greater than the number we expect.

Here we are multiplying 0.29*100 which results in 28.999999999999996 and so it is pushed into the floating numbers category and is getting printed as 29.0%

this can be avoided by rounding the floating numbers using ndarray.round( )

I would like to contribute, can I work on this issue @idanhazan ?

@idanhazan
Copy link
Author

Sure you can, thank you ;)

@ShamithaReddy
Copy link

take

@rhshadrach rhshadrach added Numeric Operations Arithmetic, Comparison, and Logical operations and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 28, 2022
@rhshadrach rhshadrach added this to the Contributions Welcome milestone Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
3 participants