Skip to content

Non-intuitive behavior when multi-indexing a Series #35349

Closed
@konstantinmiller

Description

@konstantinmiller

Most likely that is not a bug but intended behavior but I find it quite confusing.

Consider the following example

idx = pd.IndexSlice
s = pd.Series(index=pd.MultiIndex.from_tuples([('A', '0'), ('A', '1'), ('B', '0')]), 
              data=[21, 22, 23])
s.loc[idx['A', :], :]

which gives

A  0    21
   1    22
B  0    23
dtype: int64

while intuitively, one would expect

A  0    21
   1    22
dtype: int64

I would expect the latter because that's what you would get with a pd.DataFrame where the second : is referring to the column index. Not paying attention that the object is a series, gives you a completely different result than if you would have a data frame.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugError ReportingIncorrect or improved errors from pandasIndexingRelated to indexing on series/frames, not to indexes themselvesMultiIndexSeriesSeries data structure

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions