[英]Int too large to convert to C long while doing .astype(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.我正在运行一个 python 脚本,我必须使用
astype(int)
方法将字符串列从熊猫df
转换为int
。 However, I get this following error:但是,我收到以下错误:
"Python int too large to convert to C long"
My strings are all numbers in string format, up to 15 characters.我的字符串都是字符串格式的数字,最多15个字符。 Is there a way to convert this column to int type without this popping this error?
有没有办法将此列转换为 int 类型而不会弹出此错误?
You need to use .astype('int64')你需要使用 .astype('int64')
import pandas as pd
df = pd.DataFrame({'test': ['999999999999999','111111111111111']})
df['int'] = df['test'].astype('int64')
Check whether you are assigning a Large Integer values to variable.检查您是否将大整数值分配给变量。
1) Instead of applying multiplication, using power 1) 不使用乘法,而是使用幂
For example:例如:
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.