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

Problem with nlargest / nsmallest on dataframes with MultiIndex columns #23033

Closed
KristianHolsheimer opened this issue Oct 8, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@KristianHolsheimer
Copy link
Contributor

commented Oct 8, 2018

The Problem

The nlargest / nsmallest functionality is broken when applied to dataframes with MultiIndex columns. For example:

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'].

This is a problem, because this behavior is inconsistent with the usual multi-level lookup behavior.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.6.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 142 Stepping 9, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

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

@KristianHolsheimer

This comment has been minimized.

Copy link
Contributor Author

commented Oct 8, 2018

This is solved in PR #23034

@jreback jreback added this to the 0.24.0 milestone Oct 9, 2018

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