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

API: quantile function over columns transposes dataframe #35363

Open
2 tasks done
tomvansteijn opened this issue Jul 21, 2020 · 3 comments
Open
2 tasks done

API: quantile function over columns transposes dataframe #35363

tomvansteijn opened this issue Jul 21, 2020 · 3 comments
Labels

Comments

@tomvansteijn
Copy link

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

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


Code snippet

import pandas as pd
import numpy as np

df = pd.DataFrame(data={'a': np.arange(100), 'b': np.arange(100),})

df = df.quantile([0.2, 0.5, 0.8], axis=1)

Problem description

Using DataFrame.quantile over axis=1 with multiple values for q transposes the dataframe. I would expect the quantiles to appear over the specified axis, so along the columns axis when axis = 1, and along rows when axis = 0. Ofcourse, an easy fix is a call to DataFrame.transpose. Ideally this should not be necessary in my opinion.

Expected Output

Quantile values over the specified axis without transposing the dataframe.

Output of pd.show_versions()

C:\Anaconda64\lib\site-packages\setuptools\distutils_patch.py:26: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
"Distutils was imported before Setuptools. This usage is discouraged "

INSTALLED VERSIONS

commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : nl_NL.UTF-8
LOCALE : None.None

pandas : 1.0.5
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.2.0.post20200712
Cython : 0.29.21
pytest : 5.4.3
hypothesis : 5.19.3
sphinx : 3.1.2
blosc : None
feather : None
xlsxwriter : 1.2.9
lxml.etree : 4.5.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : 4.9.1
bottleneck : 1.3.2
fastparquet : None
gcsfs : None
lxml.etree : 4.5.2
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.4
pyarrow : None
pytables : None
pytest : 5.4.3
pyxlsb : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.18
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.9
numba : 0.50.1

@tomvansteijn tomvansteijn added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 21, 2020
@simonjayhawkins
Copy link
Member

Thanks @tomvansteijn for the report.

This is not a bug. This is the expected behaviour so closing. lmk if I misunderstood something and i'll reopen.

from https://pandas.pydata.org/pandas-docs/dev/reference/api/pandas.DataFrame.quantile.html

Returns
Series or DataFrame
If q is an array, a DataFrame will be returned where the
index is q, the columns are the columns of self, and the values are the quantiles.

@simonjayhawkins simonjayhawkins added Usage Question and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 21, 2020
@simonjayhawkins simonjayhawkins added this to the No action milestone Jul 21, 2020
@tomvansteijn
Copy link
Author

Thanks @simonjayhawkins for the clarification. You are right this is not a bug. In usage I think it would make more sense when the columns are q and the index is preserved when computing quantiles over the columns. Currently a transpose is needed to undo the implicit transpose in DataFrame.quantile.

Is it worthwile to label this an enhancement and reopen?

@simonjayhawkins
Copy link
Member

Is it worthwile to label this an enhancement and reopen?

sure

@simonjayhawkins simonjayhawkins changed the title BUG: quantile function over columns transposes dataframe API: quantile function over columns transposes dataframe Jul 21, 2020
@simonjayhawkins simonjayhawkins modified the milestones: No action, Contributions Welcome Jul 21, 2020
@mroeschke mroeschke added Enhancement quantile quantile method and removed API Design labels Aug 8, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants