加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python pandas插入长整数

发布时间:2020-12-20 13:31:40 所属栏目:Python 来源:网络整理
导读:我正在尝试在Pandas Dataframe中插入长整数 import numpy as npfrom pandas import DataFramedata_scores = [(6311132704823138710,273),(2685045978526272070,23),(8921811264899370420,45),(17019687244989530680L,270),(9930107427299601010L,273)]dtype
我正在尝试在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()

但是当我查看数据帧时,最后的长值现在是负数:

                       uid  score
0  6311132704823138710    273
1  2685045978526272070     23
2  8921811264899370420     45
3 -1427056828720020936    270
4 -8516636646409950606    273

uid是64位unsigned int,所以’u8’应该是正确的dtype?有任何想法吗 ?

解决方法

是的 – 这是熊猫目前的限制 – 我们计划在将来添加对无符号整数dtypes的支持.错误消息会更好:

http://github.com/pydata/pandas/issues/2355

现在,您可以将列dtype = object作为变通方法.

编辑2012-11-27

现在检测溢出,但现在将成为dtype = object,直到DataFrame更好地支持无符号数据类型.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读