Int 太大而无法在执行 .astype(int) 时转换为 C long [英] Int too large to convert to C long while doing .astype(int)
本文介绍了Int 太大而无法在执行 .astype(int) 时转换为 C long的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行一个 python 脚本,我必须使用 astype(int)<将字符串列从熊猫
df
转换为 int
/代码>方法.但是,我收到以下错误:
I'm running a python script, where I have to convert a string column from a pandas df
to int
, using the astype(int)
method. However, I get this following error:
"Python int too large to convert to C long"
我的字符串都是字符串格式的数字,最多15个字符.有没有办法将此列转换为 int 类型而不会弹出此错误?
My strings are all numbers in string format, up to 15 characters. Is there a way to convert this column to int type without this popping this error?
推荐答案
你需要使用 .astype('int64')
You need to use .astype('int64')
import pandas as pd
df = pd.DataFrame({'test': ['999999999999999','111111111111111']})
df['int'] = df['test'].astype('int64')
这篇关于Int 太大而无法在执行 .astype(int) 时转换为 C long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文