Int 太大而无法在执行 .astype(int) 时转换为 C long

Luc*_*lin 7 python numpy pandas

我运行一个python脚本,在那里我有一个字符串列从熊猫转换df到int使用astype(int)方法。但是,我收到以下错误:

"Python int too large to convert to C long"
Run Code Online (Sandbox Code Playgroud)

我的字符串都是字符串格式的数字,最多15个字符。有没有办法将此列转换为 int 类型而不会弹出此错误?

ALo*_*llz 10

你需要使用 .astype('int64')

import pandas as pd
df = pd.DataFrame({'test': ['999999999999999','111111111111111']})
df['int'] = df['test'].astype('int64')
Run Code Online (Sandbox Code Playgroud)