码迷,mamicode.com
首页 > 其他好文 > 详细

astype()函数

时间:2019-06-07 22:47:41      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:color   ast   div   bsp   log   val   ase   nbsp   with   

1astype()函数可用于转化dateframe某一列的数据类型

如下将dateframe某列的str类型转为int,注意astype()没有replace=True的用法,想要在原数据上修改,要写成如下形式。

注意只有当该列的字符串全是由纯数字构成时才可以这样写,如果混有字母,会报错:ValueError: invalid literal for int() with base 10:

利用int()函数转字符串也类似

参考:https://www.cnblogs.com/helloworldcc/p/9681546.html

app_train[[uid,index]] = app_train[[uid,index]].astype(int)

 isdigit()用于判断一个字符串是否由纯数字构成,如果是返回True,否则False

参考:https://www.runoob.com/python/att-string-isdigit.html

astype()函数

标签:color   ast   div   bsp   log   val   ase   nbsp   with   

原文地址:https://www.cnblogs.com/xxswkl/p/10989212.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!