Python Pandas插入长整数 [英] Python pandas insert long integer
问题描述
我正在尝试在Pandas Dataframe中插入长整数
I'm trying to insert long integers in a Pandas Dataframe
import numpy as np
from pandas import DataFrame
data_scores = [(6311132704823138710, 273), (2685045978526272070, 23), (8921811264899370420, 45), (17019687244989530680L, 270), (9930107427299601010L, 273)]
dtype = [('uid', 'u8'), ('score', 'u8')]
data = np.zeros((len(data_scores),),dtype=dtype)
data[:] = data_scores
df_crawls = DataFrame(data)
print df_crawls.head()
但是当我查看数据框时,长的最后一个值现在是负数:
But when I look in the dataframe, last values which are long are now negative :
uid score
0 6311132704823138710 273
1 2685045978526272070 23
2 8921811264899370420 45
3 -1427056828720020936 270
4 -8516636646409950606 273
uid是64位unsigned int,因此'u8'应该是正确的dtype?有什么想法吗?
uids are 64 bits unsigned int, so 'u8' should be the correct dtype ? Any ideas ?
推荐答案
是的-这是目前对熊猫的限制-我们确实计划在将来增加对无符号整数dtypes的支持.错误消息会更好:
Yes-- it's a present limitation of pandas-- we do plan to add support for unsigned integer dtypes in the future. An error message would be much better:
http://github.com/pydata/pandas/issues/2355
现在,您可以将列dtype=object
设为解决方法.
For now you can make the column dtype=object
as a workaround.
编辑2012-11-27
EDIT 2012-11-27
现在检测溢出,不过直到DataFrame更好地支持无符号数据类型之前,该检测现在将变为dtype = object.
Detecting overflows now, though will become dtype=object for now until DataFrame has better support for unsigned data types.
In [3]: df_crawls
Out[3]:
uid score
0 6311132704823138710 273
1 2685045978526272070 23
2 8921811264899370420 45
3 17019687244989530680 270
4 9930107427299601010 273
In [4]: df_crawls.dtypes
Out[4]:
uid object
score int64
这篇关于Python Pandas插入长整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!