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

问题描述 投票:0回答:1

我有一个带有UInt64Index的pandas数据帧'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)的行时,遇到溢出错误:

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
python pandas
1个回答
0
投票

它取决于你的sys.maxsize

import sys
print (sys.maxsize)

#9223372036854775807
© www.soinside.com 2019 - 2024. All rights reserved.