大约每10次运行中有1次我在运行此行时从pandas收到错误(KeyError:0):
[rnd.choice(indepVar[t]) for t in setTimes]
其中indepVar
是DataFrame(100,21),setTimes
是三个整数(1,10,20)的元组。大多数时候它给我一个从indepVar中随机选择的三个数字的列表。发生错误时,我会收到错误日志,如下所示。
有人能指出我,我做错了什么。谢谢!
错误日志(环境anaconda 4.3):
File "C:\Program Files\Anaconda3\lib\random.py", line 258, in choice
return seq[i]
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\core\series.py", line 603, in __getitem__
result = self.index.get_value(self, key)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\indexes\base.py", line 2169, in get_value
tz=getattr(series.dtype, 'tz', None))
File "pandas\index.pyx", line 98, in pandas.index.IndexEngine.get_value (pandas\index.c:3557)
File "pandas\index.pyx", line 106, in pandas.index.IndexEngine.get_value (pandas\index.c:3240)
File "pandas\index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas\index.c:4279)
File "pandas\src\hashtable_class_helper.pxi", line 404, in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:8564)
File "pandas\src\hashtable_class_helper.pxi", line 410, in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:8508)
KeyError: 0