How do I get conversion with "OverflowError: Python int too large to convert to C long" error working on Windows Server 2012?
How do I get conversion with "OverflowError: Python int too large to convert to C long" error working on Windows Server 2012?
当 运行 在 Anaconda Python 2.7.12,Pandas 18.1,Windows 服务器 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 OS。如果是这样,我如何在 Windows 上进行这项工作?
此外,data.txt 的大小仅为 172 KB。如果有帮助,data.txt 采用这种形式:
x|y
99999917|099999927 9991
99999911|999999979 9994
99999912|999999902 9992
int
被 numpy 解释为 np.int_
dtype,它对应于 C 整数。在 Windows 上,即使在 64 位系统上,这也是一个 32 位整数。
因此,如果您需要转换更大的值,请使用
指定一个 64 位整数
.astype('int64')
当 运行 在 Anaconda Python 2.7.12,Pandas 18.1,Windows 服务器 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 OS。如果是这样,我如何在 Windows 上进行这项工作?
此外,data.txt 的大小仅为 172 KB。如果有帮助,data.txt 采用这种形式:
x|y
99999917|099999927 9991
99999911|999999979 9994
99999912|999999902 9992
int
被 numpy 解释为 np.int_
dtype,它对应于 C 整数。在 Windows 上,即使在 64 位系统上,这也是一个 32 位整数。
因此,如果您需要转换更大的值,请使用
指定一个 64 位整数.astype('int64')