m0_56684907
2021-05-17 15:51
采纳率: 100%
浏览 90
已采纳

Python用while循环下标越界怎么解决?

报错内容:
Traceback (most recent call last):
File "C:/Users/kh/PycharmProjects/pythonProject1/main.py", line 24, in <module>
ddh1 = df1.iloc[a,7]
File "C:\Users\kh\.conda\envs\pythonProject1\lib\site-packages\pandas\core\indexing.py", line 889, in __getitem__
return self._getitem_tuple(key)
File "C:\Users\kh\.conda\envs\pythonProject1\lib\site-packages\pandas\core\indexing.py", line 1450, in _getitem_tuple
self._has_valid_tuple(tup)
File "C:\Users\kh\.conda\envs\pythonProject1\lib\site-packages\pandas\core\indexing.py", line 723, in _has_valid_tuple
self._validate_key(k, i)
File "C:\Users\kh\.conda\envs\pythonProject1\lib\site-packages\pandas\core\indexing.py", line 1358, in _validate_key
self._validate_integer(key, axis)
File "C:\Users\kh\.conda\envs\pythonProject1\lib\site-packages\pandas\core\indexing.py", line 1444, in _validate_integer
raise IndexError("single positional indexer is out-of-bounds")
IndexError: single positional indexer is out-of-bounds

 

 

12行到17行的代码 我想让他循环起来 就用了20行到27行的代码,但是到了24行就开始报错,该怎么解决,还有我发现执行if语句后变量a的值不会加1

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • 已采纳

    第二个循环之前a和b要重新设置为0

    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题