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

Enhancement: code sugar for index.get_level_values #31444

Closed
mhooreman opened this issue Jan 30, 2020 · 2 comments
Closed

Enhancement: code sugar for index.get_level_values #31444

mhooreman opened this issue Jan 30, 2020 · 2 comments
Labels
Enhancement Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@mhooreman
Copy link

Code Sample, a copy-pastable example if possible

data.index.get_level_values('foobar') == 42
# would like to have data.index['foobar'] == 42

Problem description

Filtering data frame row by one column of multi index is quite common.

Unless I've missed something, the current implementation need get_index_value. It would be nice to have a more direct way to select one MultiIndex column, like we can do with the data frame columns.

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.4.final.0
python-bits      : 64
OS               : Linux
OS-release       : 4.15.0-74-generic
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 0.25.3
numpy            : 1.18.1
pytz             : 2019.3
dateutil         : 2.8.1
pip              : 20.0.2
setuptools       : 45.1.0
Cython           : 0.29.14
pytest           : None
hypothesis       : None
sphinx           : 2.3.1
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : 4.4.2
html5lib         : None
pymysql          : None
psycopg2         : 2.8.4 (dt dec pq3 ext lo64)
jinja2           : 2.10.3
IPython          : 7.11.1
pandas_datareader: None
bs4              : 4.8.2
bottleneck       : 1.3.1
fastparquet      : None
gcsfs            : None
lxml.etree       : 4.4.2
matplotlib       : 3.1.2
numexpr          : 2.7.1
odfpy            : None
openpyxl         : 3.0.3
pandas_gbq       : None
pyarrow          : None
pytables         : None
s3fs             : None
scipy            : 1.4.1
sqlalchemy       : None
tables           : None
xarray           : None
xlrd             : 1.2.0
xlwt             : None
xlsxwriter       : None

@jorisvandenbossche
Copy link
Member

Yes, I think it is correct there is currently no other way. Some related isues: #10816 (about easier way to select a single or multiple levels of a MultiIndex) and #8162 (about selecting an index as level as if it would be a column, which could also solve your specific use case)

@simonjayhawkins simonjayhawkins added Enhancement Indexing Related to indexing on series/frames, not to indexes themselves labels Apr 25, 2020
@mroeschke
Copy link
Member

Thanks for the request but it appears this hasn't gotten traction in a while so closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

5 participants