Skip to content

BUG: DataFrame.loc with a MultiIndex does not always collapse scalar levels #10552

Open
@shoyer

Description

@shoyer

All of the following should be equivalent:

In [21]: df = pd.DataFrame({'a': [1], 'b': [2], 'c': [3]}).set_index(['a', 'b'])

In [22]: df.loc[1]
Out[22]:
   c
b
2  3

In [23]: df.loc[(1,), slice(None)]
Out[23]:
   c
b
2  3

In [24]: df.loc[(1, slice(None)), slice(None)]
Out[24]:
     c
a b
1 2  3

In the last output, there should no longer be a level a.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesMultiIndex

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions