Closed
Description
Problem description
With a Series with integer index, __getitem__
/ [] does positional indexing, but when you have a duplicate index and use a list indexer, you get a "ValueError: cannot reindex from a duplicate axis" (with .loc
the same works OK)
Code Sample, a copy-pastable example if possible
In [28]: s = pd.Series(range(3), index=[1, 2, 3])
In [29]: s[1]
Out[29]: 0
In [30]: s[[1]]
Out[30]:
1 0
dtype: int64
# duplicate index
In [31]: s = pd.Series(range(3), index=[1, 1, 3])
In [32]: s[1]
Out[32]:
1 0
1 1
dtype: int64
In [33]: s[[1]]
...
ValueError: cannot reindex from a duplicate axis
In [34]: s.loc[[1]]
Out[34]:
1 0
1 1
dtype: int64
It seems to only fail for integer index (eg with a string index s = pd.Series(range(3), index=['a', 'a', 'b'])
the equivalent works ok)