![](/img/trans.png)
[英]OverflowError: Python int too large to convert to C long while locating data by pandas UInt64Index
[英]Int too large to convert to C long while doing .astype(int)
我正在運行一個 python 腳本,我必須使用astype(int)
方法將字符串列從熊貓df
轉換為int
。 但是,我收到以下錯誤:
"Python int too large to convert to C long"
我的字符串都是字符串格式的數字,最多15個字符。 有沒有辦法將此列轉換為 int 類型而不會彈出此錯誤?
你需要使用 .astype('int64')
import pandas as pd
df = pd.DataFrame({'test': ['999999999999999','111111111111111']})
df['int'] = df['test'].astype('int64')
檢查您是否將大整數值分配給變量。
1) 不使用乘法,而是使用冪
例如:
x = [10**i for i in range(1,1000)] instead of [10*i for i in range(1,1000)] ,which will cross the variable limit
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.