目前我有一个索引错误问题,我想了解一下。
如何解读if len(arr) and (arr.max() >= len_axis or arr.min() < -len_axis):
?
即,我不知道它指的是哪个数组,即与我的代码相关的len(arr)
或len_axis
。
输出:
IndexError Traceback (most recent call last)
<ipython-input-27-f9c0ccc07fa7> in <module>
----> 1 Engine_EO4(Input_Data)
<ipython-input-25-7d8bbce39c4d> in Engine_EO4(Input_Data)
234 col = i
235 row = y
--> 236 j.append(ValveCover.iloc[row+6:,[col,col+1,col+2,col+5,col+6,col+9, col+10]])
237 break
238 df=j[0].astype(float).round(6)
F:ProgramFilesAnacondalibsite-packagespandascoreindexing.py in __getitem__(self, key)
1760 except (KeyError, IndexError, AttributeError):
1761 pass
-> 1762 return self._getitem_tuple(key)
1763 else:
1764 # we by definition only have the 0th axis
F:ProgramFilesAnacondalibsite-packagespandascoreindexing.py in _getitem_tuple(self, tup)
2065 def _getitem_tuple(self, tup: Tuple):
2066
-> 2067 self._has_valid_tuple(tup)
2068 try:
2069 return self._getitem_lowerdim(tup)
F:ProgramFilesAnacondalibsite-packagespandascoreindexing.py in _has_valid_tuple(self, key)
701 raise IndexingError("Too many indexers")
702 try:
--> 703 self._validate_key(k, i)
704 except ValueError:
705 raise ValueError(
F:ProgramFilesAnacondalibsite-packagespandascoreindexing.py in _validate_key(self, key, axis)
2007 # check that the key does not exceed the maximum size of the index
2008 if len(arr) and (arr.max() >= len_axis or arr.min() < -len_axis):
-> 2009 raise IndexError("positional indexers are out-of-bounds")
2010 else:
2011 raise ValueError(f"Can only index by location with a [{self._valid_types}]")
IndexError: positional indexers are out-of-bounds
您试图调用的索引大于数组的最大长度或小于数组的最小长度。
该错误显示了被调用以执行iloc的包的沿袭。如果您查看ValveCover
数据帧的维度,并将它们与您试图在iloc中调用的索引进行比较,您应该能够找到差异。