OverflowError:Python int太大,无法通过pandas UInt64Index定位数据时转换为C long

时间:2018-02-27 17:07:26

标签: python pandas

我有一个熊猫数据框' df'使用UInt64Index:

  

df.info()

<class 'pandas.core.frame.DataFrame'>
UInt64Index: 132 entries, 3377906280028510514 to 9377906289175510514
Columns: 132 entries, 3377906280028510514 to 9377906289175510514
dtypes: float64(132)
memory usage: 142.2 KB

当我尝试找到最后一个索引值为9377906289175510514(尚未达到2 ** 64 - 1)的行时,会遇到OverflowError:

  

df.loc [9377906282776510514]

OverflowError                             Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/pandas/core/indexing.py in _has_valid_type(self, key, axis)
   1432                 key = self._convert_scalar_indexer(key, axis)
-> 1433                 if not ax.contains(key):
   1434                     error()

~/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py in contains(self, key)
   1661         try:
-> 1662             return key in self._engine
   1663         except TypeError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.__contains__()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.UInt64HashTable.__contains__()

OverflowError: Python int too large to convert to C long

1 个答案:

答案 0 :(得分:0)

这取决于你的sys.maxsize

import sys
print (sys.maxsize)

#9223372036854775807