如何解决在Windows Server 2012上出现“OverflowError:Python int too large to convert to C long”错误的转换问题?

3
在运行此代码时,使用Anaconda Python 2.7.12和Pandas 18.1在Windows Server 2012上:
df['z'] = df['y'].str.replace(' ', '').astype(int)

我遇到了这个错误:
OverflowError: Python int too large to convert to C long

在MacOS 10.11或Ubuntu 14.04上我没有遇到这个错误。我从其他地方读到说,Windows C++编译器对long的定义与类Unix操作系统不同。如果是这样,我该如何在Windows上使它工作?

此外,data.txt文件大小仅为172 KB。如果有帮助的话,data.txt的格式如下:

x|y
99999917|099999927 9991
99999911|999999979 9994
99999912|999999902 9992

2
尝试使用.astype('int64') - 在Windows上,int始终为32位。 - chrisb
可以了。把它作为答案,我会接受它。 - scottlittle
1个回答

4

int 在numpy中被解读为np.int_数据类型,对应于C整数。在Windows上,即使是64位系统,它仍然是32位整数。

因此,如果您需要转换较大的值,请使用以下方法指定64位整数

.astype('int64')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接