美文网首页机器学习与数据挖掘我爱编程
pandas使用技巧【9】如何改变Series的data typ

pandas使用技巧【9】如何改变Series的data typ

作者: 夜雨寒山 | 来源:发表于2017-11-09 13:15 被阅读535次
简介: 本文主要介绍如何改变Series的data type。
查看数据类型
dataframe.dtypes
使用astype方法

cast the type as follows

dataframe.colname.astype('float')
dataframe.colname.astype('object')

也可以把string数据去掉部门非数字类型的字符后cast type

如去掉¥符号,在转换成int:
dataframe.colname.str.replace("¥",  "").astype('int')
读取数据的时候更改
pd.read_csv("data", dtype = {"colname" : float})

附上小哥哥的视频链接Data analysis in Python with pandas
Youtube 🔗
哔哩哔哩 🔗

所有文章列表
pandas使用技巧总览

相关文章

网友评论

    本文标题:pandas使用技巧【9】如何改变Series的data typ

    本文链接:https://www.haomeiwen.com/subject/rhmpmxtx.html