Python 官方文档:入门教程 => 点击学习
1.导入数据import numpy as npimport csv2.获取数据iris_data=[]with open("iris.csv") as csvfile: csv_reader=csv.reader(csvfile)
1.导入数据import numpy as npimport csv2.获取数据iris_data=[]with open("iris.csv") as csvfile: csv_reader=csv.reader(csvfile) #用csv.reader读取csvfile文件 birth_header=next(csv_reader) #读取第一行各列标题 for row in csv_reader: iris_data.append(row)3.数据清理,去掉索引号iris_list=[]for row in iris_data: iris_list.append(tuple(row[1:]))iris_list4.数据统计(1)创建数据类型datatype=np.dtype([("Sepal.Length",np.str_,40), ("Sepal.Width",np.str_,40), ("Petal.Length",np.str_,40), ("Petal.Width",np.str_,40), ("Species",np.str_,40)])datatype(2)创建二维数组iris_data=np.array(iris_list,dtype=datatype)iris_data(3)将待处理数据的类型转化为float类型PetalLength=iris_data["Petal.Length"].astype(float)PetalLength(4)排序np.sort(PetalLength)(5)数据去重np.unique(PetalLength)(6)对指定列求和、均值、标准差、方差、最小值及最大值print("sum:",np.sum(PetalLength))print("mean:",np.mean(PetalLength))print("std:",np.std(PetalLength))print("var:",np.var(PetalLength))print("min:",np.min(PetalLength))print("max:",np.max(PetalLength))
运行结果如下:
来源地址:https://blog.csdn.net/m0_56107252/article/details/127324725
--结束END--
本文标题: Python:读取iris数据集中鸢尾花的萼片,花瓣长度,并对其进行排序、去重、并求出和,累计和,均值,标准差、方差、最大值和最小值
本文链接: https://www.lsjlt.com/news/433561.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0