“OverflowError:无法将浮点无穷大转换为整数”,请检查

时间:2015-07-25 12:02:48

标签: python infinity

我收到错误

  

OverflowError:无法将float无穷大转换为整数

来自此代码:

if not math.isinf(data['occurrence'][0][key]):
                   df.set_value(df.date == key, name, data['occurrence'][0][key])

为什么set_value部分会被执行?如何解决这个问题?

修改

完整堆栈跟踪:

  

Traceback(最近一次调用最后一次):文件“aggregateData.py”,第27行,   在       df.set_value(df.date == key,name,data ['occurrence'] [0] [key])#update df文件“/usr/local/lib/python2.7/dist-packages/pandas/core/ frame.py“,行   1690,在set_value中       self.loc [index,col] = value文件“/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.py”,行   114,在 setitem       indexer = self._get_setitem_indexer(key)File“/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.py”,line   106,在_get_setitem_indexer中       return self._convert_tuple(key,is_setter = True)File“/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.py”,line   155,在_convert_tuple中       idx = self._convert_to_indexer(k,axis = i,is_setter = is_setter)文件“/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.py”,   第1025行,在_convert_to_indexer中       obj = self._convert_scalar_indexer(obj,axis)文件“/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.py”,行   163,在_convert_scalar_indexer中       return ax._convert_scalar_indexer(key,kind = self.name)文件“/usr/local/lib/python2.7/dist-packages/pandas/core/index.py”,行   806,在_convert_scalar_indexer中       return to_int()文件“/usr/local/lib/python2.7/dist-packages/pandas/core/index.py”,行   787,在to_int       ikey = int(key)OverflowError:无法将float infinity转换为integer

1 个答案:

答案 0 :(得分:0)

堆栈跟踪的结束

"/usr/local/lib/python2.7/dist-packages/pandas/core/index.py", line 787, in to_int ikey = int(key) OverflowError: cannot convert float infinity to integer

强烈建议无法转换为整数(特别是考虑到data['occurrence'][0][key]似乎是1. print key打印的是什么?