【发布时间】:2019-08-16 09:14:08
【问题描述】:
我正在尝试从 pandas 数据框中获取多行。
df.iloc[1]
可以用来获取一行,但是下面的代码遇到错误。
df.iloc[1,3,8]
错误
----------------------------------------------- ---------------------------- IndexingError Traceback(最近调用 最后)在() ----> 1 df.iloc[1,3,8]
~/anaconda3/envs/tf11/lib/python3.6/site-packages/pandas/core/indexing.py 在 getitem(self, key) 1323 中,除了 (KeyError, IndexError): 1324 通过 -> 1325 return self._getitem_tuple(key) 1326 else: 1327 key = com._apply_if_callable(key, self.obj)
~/anaconda3/envs/tf11/lib/python3.6/site-packages/pandas/core/indexing.py 在_getitem_tuple(自我,tup)1660年定义_getitem_tuple(自我, tup): 1661 -> 1662 self._has_valid_tuple(tup) 1663 try: 1664 return self._getitem_lowerdim(tup)
~/anaconda3/envs/tf11/lib/python3.6/site-packages/pandas/core/indexing.py 在 _has_valid_tuple(self, key) 186 for i, k in enumerate(key): 187如果我> = self.obj.ndim: --> 188 raise IndexingError('Too many indexers') 189 如果不是 self._has_valid_type(k, i): 190 raise ValueError("基于位置的索引只能有 [%s]"
IndexingError:索引器过多
【问题讨论】: