Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Index Slice Selection in Series #6018

theandygross opened this issue Jan 20, 2014 · 1 comment · Fixed by #6022


Copy link

commented Jan 20, 2014

Slicing in Series with MultiIndex does not seem to work on master with .ix or .loc. This is not comparable with previous versions.

In [54]:  

s = pd.Series([1,2,3])
s.index = pd.MultiIndex.from_tuples([(0,0),(1,1), (2,1)])


1    2
2    3

In [56]:  



Traceback (most recent call last)
<ipython-input-56-3163789d3245> in <module>()
----> 1 s.ix[:,1]

/cellar/users/agross/anaconda2/lib/python2.7/site-packages/pandas-0.13.0_120_gdd89ce4-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in __getitem__(self, key)
     52                 pass
---> 54             return self._getitem_tuple(key)
     55         else:
     56             return self._getitem_axis(key, axis=0)

/cellar/users/agross/anaconda2/lib/python2.7/site-packages/pandas-0.13.0_120_gdd89ce4-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in _getitem_tuple(self, tup)
    594         # no multi-index, so validate all of the indexers
--> 595         self._has_valid_tuple(tup)
    597         # ugly hack for GH #836

/cellar/users/agross/anaconda2/lib/python2.7/site-packages/pandas-0.13.0_120_gdd89ce4-py2.7-linux-x86_64.egg/pandas/core/indexing.pyc in _has_valid_tuple(self, key)
    103         for i, k in enumerate(key):
    104             if i >= self.obj.ndim:
--> 105                 raise IndexingError('Too many indexers')
    106             if not self._has_valid_type(k, i):
    107                 raise ValueError("Location based indexing can only have [%s] "

IndexingError: Too many indexers

This comment has been minimized.

Copy link

commented Jan 21, 2014

Allowing multiple indexers on a Series IMHO is wrong and shouldn't be allowed; instead you should use xs
(to be fair this didn't exist in 0.12, that's why its allowed :)

so fixed this, and fixed xs on a Series which wasn't working properly


Series.xs(1,level=1) is what you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.