We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The nlargest / nsmallest functionality is broken when applied to dataframes with MultiIndex columns. For example:
nlargest
nsmallest
MultiIndex
columns = pd.MultiIndex.from_tuples([('x', 'a'), ('x', 'b'), ('y', 'c'), ('y', 'd')]) values = np.random.rand(5, 4) df = pd.DataFrame(data=values, columns=columns) df.nlargest(3, ('x', 'a'))
This raises an error because the multi-level lookup ('x', 'a') is interpreted as a list of column names ['x', 'a'].
('x', 'a')
['x', 'a']
This is a problem, because this behavior is inconsistent with the usual multi-level lookup behavior.
pd.show_versions()
pandas: 0.23.4 pytest: None pip: 10.0.1 setuptools: 39.0.1 Cython: None numpy: 1.14.5 scipy: 1.1.0 pyarrow: None xarray: None IPython: 6.5.0 sphinx: None patsy: None dateutil: 2.7.3 pytz: 2018.5 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: 3.0.0 openpyxl: None xlrd: None xlwt: None xlsxwriter: None 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
The text was updated successfully, but these errors were encountered:
This is solved in PR #23034
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
The Problem
The
nlargest
/nsmallest
functionality is broken when applied to dataframes withMultiIndex
columns. For example:This raises an error because the multi-level lookup
('x', 'a')
is interpreted as a list of column names['x', 'a']
.This is a problem, because this behavior is inconsistent with the usual multi-level lookup behavior.
Output of
pd.show_versions()
pandas: 0.23.4
pytest: None
pip: 10.0.1
setuptools: 39.0.1
Cython: None
numpy: 1.14.5
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
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
The text was updated successfully, but these errors were encountered: