Python-辨析type/dtype/astype用法
Python中与数据类型相关函数及属性有如下三个:type/dtype/astype。
名称 | 描述 |
---|---|
type() | 返回参数的数据类型 |
dtype | 返回数组中元素的数据类型 |
astype() | 对数据类型进行转换 |
- type()用于获取数据类型
#type用于获取数据类型
import numpy as np
a=[1,2,3]
print(type(a))
#>>><class 'list'>
b=np.array(a)
print(type(b))
#>>><class 'numpy.ndarray'>
- dtype用于获取数组中元素的类型
#dtype用于获取数组中元素的类型
print(b.dtype)
#>>>int64x,y,z=1,2,3
c=np.array([x,y,z])
print(c.dtype)
#>>>int64d=np.array([1+2j,2+3j,3+4j])
print(d.dtype)
#>>>complex128
- astype()修改数据类型
Array中用法
#astype修改数据类型
e=np.linspace(1,5,20)
print(e)
#>>>
'''
[1. 1.21052632 1.42105263 1.63157895 1.84210526 2.052631582.26315789 2.47368421 2.68421053 2.89473684 3.10526316 3.315789473.52631579 3.73684211 3.94736842 4.15789474 4.36842105 4.578947374.78947368 5. ]
'''
print(e.dtype)
#>>>float64e=e.astype(int)
print(e)
#>>>[1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 5]
print(e.dtype)
#>>>int64
Dataframe中用法:转换指定字段数据的类型
import pandas as pd
e=np.linspace(1,5,20)
edf=pd.DataFrame(e)
edf[0].head(3)
#>>>
0 1.000000
1 1.210526
2 1.421053
Name: 0, dtype: float64print(edf[0].dtype)
#>>>float64edf[0]=edf[0].astype(int)
edf[0].head(3)
#>>>
0 1
1 1
2 1
Name: 0, dtype: int64print(edf[0].dtype)
#>>>int64
Python-辨析type/dtype/astype用法相关推荐
- Python中辨析type/dtype/astype用法
Python中与数据类型相关函数及属性有如下三个:type/dtype/astype. 名称 描述 type() 返回参数的数据类型 dtype 返回数组中元素的数据类型 astyp ...
- Python中type/dtype/astype用法
Python中与数据类型相关函数及属性有如下三个:type/dtype/astype. 名称 描述 type() 返回参数的数据类型 dtype 返回数组中元素的数据类型 astype() 对数据类型 ...
- python中type(),dtype(),astype()的区别
python中type(),dtype(),astype()的区别 type(): 返回的是数据结构的类型(list, dict,numpy.ndarry) >>> k = [1, ...
- python中type dtype astype 的用法
1.type 获取数据类型 2.dtype 数组元素的类型 3.astype 修改数据类型 参考:http://www.cnblogs.com/fuhang/p/8045973.html
- python中astype用法_浅谈python 中的 type(), dtype(), astype()的区别
如下所示: 函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list. ...
- python中dtype什么意思_浅谈python 中的 type(), dtype(), astype()的区别
如下所示: 函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list. ...
- python dtype什么意思_浅谈python 中的 type(), dtype(), astype()的区别
如下所示: 函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list. ...
- python 中的 type(), dtype(), astype()的区别
函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等) 备注:1)由于 list.dict 等 ...
- python中type,dtype,asdtype的作用与使用
demo代码: import numpy as np a = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]) b = np.float32([[1,2,3 ...
最新文章
- linux内核网络协议栈--监控和调优:发送数据(三十)
- Java程序内存分析:使用mat工具分析内存占用
- C:输入数字计数(数组方法)
- 牛客网(剑指offer) 第十四题 链表中倒数第k个节点
- js 循环 等待异步执行完再执行_JS异步执行机制——事件循环(Event Loop)
- iframe缓存无法清空_详解Http缓存机制
- V1.8 - 2006.09.09
- 转载JMF多媒体doc教程
- 不当IT民工——技术带来质的飞跃
- layey图片内容不居中
- 20145316《信息安全系统设计基础》期中总结
- GitHub绑定阿里云域名
- android自定义大转盘,Android使用surfaceView自定义抽奖大转盘
- 搭建一个个人网站需要多少钱预算?
- 电脑鼠标右键菜单反应慢怎么办?右键菜单反应慢解决办法
- 自动化测试的三种测试报告模板
- OpenWRT安装SIM7600CE 4G模块驱动
- 建模知识2: ROC、AUC、K-S曲线
- 【Linux】解决笔记本合盖子休眠的问题
- 对于自我的反省 - 对底层人民认知产生的商业思考
热门文章
- 想用云电脑,新手怎么免费
- 计算机科学导论学习笔记(三)
- 鬼泣最稳定的服务器,《鬼泣巅峰之战》选什么服务器好 新手开局服务器选择指南...
- 新概念二册 Lesson 26 The best art critics最佳艺术评论家 ( 宾语从句+一般现在时现在进行时宾语从句)
- python学习,pip 模块-数据库(mysql)-excel操作-写日志-邮件-md5加密
- tars框架 php,tars框架安装
- pdf翻译成中文并导出word
- Excel 生成 随机 乘法 打印版
- linux网卡启动失败参考
- 关于ClassLoader的学习笔记,详解版