簡體   English   中英

OverflowError:通過熊貓UInt64Index定位數據時,Python int太大而無法轉換為C

[英]OverflowError: Python int too large to convert to C long while locating data by pandas UInt64Index

我有一個帶有UInt64Index的熊貓數據框“ df”:

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

這取決於您的sys.maxsize

import sys
print (sys.maxsize)

#9223372036854775807

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM