其他分享
首页 > 其他分享> > pandas 补充笔记:转换&提取类型

pandas 补充笔记:转换&提取类型

作者:互联网

0 所用的数据

1 查看类型(.dtypes)

nodes.dtypes
'''
y                float64
x                float64
street_count       int64
highway           object
geometry        geometry
osmid              int64
dtype: object
'''

 2 选取类型(select_dtypes)

2.1 选择指定类型

nodes.select_dtypes(include='int')

 2.2 选择所有数值类型

nodes.select_dtypes(include='number')

2.3 指定某几个类型

nodes.select_dtypes(include=['int64','object'])

 2.4 排除

exclude=... 使用的方法2.1,2.2,2.3都有

3 转换类型

3.1 通用方法 (astype)

nodes['street_count'].astype('float64')
'''
osmid
99936         3.0
99937         3.0
101842        3.0
101843        4.0
101851        3.0
             ... 
9221415719    2.0
9273527714    2.0
9273563732    2.0
9281454429    3.0
9281454433    3.0
Name: street_count, Length: 3305, dtype: float64
'''

3.2 将string 转换成number(pd.to_numeric) 

先有:

 

标签:提取,float64,笔记,dtypes,3.0,类型,nodes,pandas,select
来源: https://blog.csdn.net/qq_40206371/article/details/121659146