Richard Stanton
unread,May 20, 2013, 2:15:25 PM5/20/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pyd...@googlegroups.com
I just tracked a bug in my code down to executing something like the
following code, which produces the error listed when the index is not
unique. Is the error intentional, or should this code work? (It's not
obvious to me).
Thanks.
Richard Stanton
df = DataFrame({'A' : [1,2,3,4], 'B' : [3, 4, 5, 6]}, index = [0,1,0,1])
df.loc[1:]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-46-1cdf797dd554> in <module>()
1 df = DataFrame({'A' : [1,2,3,4], 'B' : [3, 4, 5, 6]}, index =
[0,1,0,1])
----> 2 df.loc[1:]
/RHS/packages/anaconda/pandas/pandas/core/indexing.pyc in
__getitem__(self, key)
684 return self._getitem_tuple(key)
685 else:
--> 686 return self._getitem_axis(key, axis=0)
687
688 def _getitem_axis(self, key, axis=0):
/RHS/packages/anaconda/pandas/pandas/core/indexing.pyc in
_getitem_axis(self, key, axis)
760
761 if isinstance(key, slice):
--> 762 return self._get_slice_axis(key, axis=axis)
763 elif com._is_bool_indexer(key):
764 return self._getbool_axis(key, axis=axis)
/RHS/packages/anaconda/pandas/pandas/core/indexing.pyc in
_get_slice_axis(self, slice_obj, axis)
704
705 labels = obj._get_axis(axis)
--> 706 indexer = labels.slice_indexer(slice_obj.start,
slice_obj.stop, slice_obj.step)
707
708 if isinstance(indexer, slice):
/RHS/packages/anaconda/pandas/pandas/core/index.pyc in slice_indexer(self,
start, end, step)
1199
1200 # loc indexers
-> 1201 return Index(start_slice) & Index(end_slice)
1202
1203 def slice_locs(self, start=None, end=None):
/RHS/packages/anaconda/pandas/pandas/core/index.pyc in __new__(cls, data,
dtype, copy, name, **kwargs)
111 elif np.isscalar(data):
112 raise ValueError('Index(...) must be called with a
collection '
--> 113 'of some kind, %s was passed' %
repr(data))
114 else:
115 # other iterable of some kind
ValueError: Index(...) must be called with a collection of some kind, 4
was passed