熊猫尾部索引0越界



我收到一个"索引0超出边界"使用下面的代码出错。我已经用尽了我的选项调试自己,并将非常感谢一些帮助我解决这个问题。谢谢你!

数据:

game_info.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 30362 entries, 0 to 30361
Data columns (total 10 columns):
#   Column         Non-Null Count  Dtype         
---  ------         --------------  -----         
0   competitionId  30362 non-null  Int64         
1   gameId         30349 non-null  Int64         
2   gameDate       30362 non-null  datetime64[ns]
3   gameTime       30362 non-null  datetime64[ns]
4   awayId         30362 non-null  int64         
5   homeId         30362 non-null  int64         
6   awayScore      30362 non-null  int64         
7   homeScore      30362 non-null  int64         
8   homeWin        29889 non-null  Int64         
9   homePush       30362 non-null  Int64         
dtypes: Int64(4), datetime64[ns](2), int64(4)
memory usage: 2.4 MB
game_info.head()
homePush00000

该错误提到值的结果为空(大小为0),因此您无法获得它的0索引。

试着调试你的代码,看看为什么会发生这种情况(空结果)。

如果它应该是空的使用[0]前请检查值的长度

if len(...values) == 0:
Do something
else:
Do something else

你也可以使用"try,除了"但最好找到另一种方法(比如"如果")。声明中)

如果这个答案不能解决你的问题,请添加更多信息。

最新更新