Reputation: 514
I get the error
OverflowError: cannot convert float infinity to integer
from this code:
if not math.isinf(data['occurrence'][0][key]):
df.set_value(df.date == key, name, data['occurrence'][0][key])
How come the set_value
part gets executed anyway? How to fix this?
EDIT:
Full Stack Trace:
Traceback (most recent call last): File "aggregateData.py", line 27, in df.set_value(df.date == key, name, data['occurrence'][0][key]) #update df File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 1690, in set_value self.loc[index, col] = value File "/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.py", line 114, in setitem indexer = self._get_setitem_indexer(key) File "/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.py", line 106, in _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, in _convert_tuple idx = self._convert_to_indexer(k, axis=i, is_setter=is_setter) File "/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.py", line 1025, in _convert_to_indexer obj = self._convert_scalar_indexer(obj, axis) File "/usr/local/lib/python2.7/dist-packages/pandas/core/indexing.py", line 163, in _convert_scalar_indexer return ax._convert_scalar_indexer(key, kind=self.name) File "/usr/local/lib/python2.7/dist-packages/pandas/core/index.py", line 806, in _convert_scalar_indexer return to_int() File "/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
Upvotes: 1
Views: 5834
Reputation: 51998
The end of the stack trace
"/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
strongly suggests that it is the key that can't be converted to an integer (especially given the fact that data['occurrence'][0][key]
seems to be 1. What does print key
print?
Upvotes: 0