-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
BugIndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesMultiIndexNeeds TestsUnit test(s) needed to prevent regressionsUnit test(s) needed to prevent regressions
Description
Code Sample, a copy-pastable example if possible
import pandas as pd
s = pd.Series([1, 2], pd.MultiIndex.from_arrays([['a', 'b']]))
print(s.loc[['a', 'a', 'b', 'b']])
Problem description
This prints the full series, not the series with repeated elements:
a 1
b 2
dtype: int64
Expected Output
a 1
a 1
b 2
b 2
dtype: int64
An easy work around is to use s.reindex(['a', 'a', 'b', 'b'])
instead. But loc
and reindex
should return the same thing when all labels are found.
Output of pd.show_versions()
pandas 0.22.0
I think this behavior is present on earlier versions of pandas, too, but previously it was very difficult to construct a MultiIndex with only a single level, because they were automatically turned in a base Index.
Metadata
Metadata
Assignees
Labels
BugIndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesMultiIndexNeeds TestsUnit test(s) needed to prevent regressionsUnit test(s) needed to prevent regressions