import numpy as np
# 一.基本数据类型
# bool:由所在平台决定其精度的整数int32,int64---字长
# int:----------------int32,in64
# 另外:int8\int16\int32\float32\float64...
# 二.数据类型转换
# eg:
# np.float64(n)
# eg:
value1=np.bool(10)
value2=np.bool(0)
print(value1,value2) #True False
# eg:
value3=np.float64(True)
print(value3) #1.0
# 三.定义数据类型(数据存储结构)
# eg:
# 创建一个存储餐饮企业库存信息的数据类型.其中:
# (1) 用一个长度为40个字符的字符串来记录商品名称
# (2) 用一个64位的证书来记录商品的库存
# (3) 用一个64位的单精度浮点数来记录商品的价格
#(dataframe)
df = np.dtype([('name',np.str_,40),('numitems',np.int64),('price',np.float64)])
items = np.array([('tomataoes',100,2),('cabbages',200,0.5),('apple',50,4.5)],dtype=df)
print(items)
#[('tomataoes', 100, 2. ) ('cabbages', 200, 0.5) ('apple', 50, 4.5)]
print(df['name']) #<U40
print(df['numitems']) #int64
print(type(df['name'])) #<class 'numpy.dtype'>
数据分析(numpy)----04.数据类型
最新推荐文章于 2022-10-14 19:41:29 发布