热线电话:13121318867

登录
2019-02-14 阅读量: 659
如何在数据框中转换为长度为20的数字数据

我的csv文件有很少的长度为20的数字数据。当我在数据帧中读取它时,它被读作dtype对象。我需要将所有数值数据转换为Integer。

我的数据是csv看起来像:

emp_id,age,salary,marital

21012334509821345944,22,4500,married

21012334509821345945,22,4510,single

21012334509821345946,22,45040,married

21012334509821345947,22,41500,single

21012334509821345948,22,54500,single

21012334509821345949,22,64500,married

我试过了 :

d1 = pd.read_csv('D:\\Exercise\\test.csv')

d1.set_index('emp_id',inplace = True)

d1.index = d1.index.map(int) #OverflowError: int too big to convert

print(d1.index.values)

如果我评论索引地图,我得到如下输出:['21012334509821345944''21012334509821345945''21012334509821345946''21012334509821345947''21012334509821345948''21012334509821345949']

解决办法:

Pandas / Numpy将整数保持为64位。也许更大,但重点是有限制。需要将它们存储为,dtype object但值为int。

这是一种方式:

df.emp_id.values[:] = [*map(int, df.emp_id)]

0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子