Skip to content

Feature request: Access multiindex by name #14152

Closed
@dov

Description

@dov

Code Sample, a copy-pastable example if possible

I have not found an easy way to access a column of a multi index by name. Consider the following code:

import pandas as pd
df = pd.DataFrame([[1,1,10,200],
                   [1,2,11,201],
                   [1,3,12,202],
                   [2,1,13,210],
                   [2,2,14,230]],
                  columns=list('ABCD')).set_index(['A','B'])
ii = df.index

To access the values of column B i can e.g. do:

df.reset_index('B').B.tolist()

or

[v[1] for v in ii.tolist()]

Both of there are somewhat cumbersome What I'm proposing is to add similar shorcut access to a multiindex just like a dataframe. E.g.

ii.B

or

ii['B']

that would return the same list as in the two examples above.

output of pd.show_versions()

0.18.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions