实验三 |
您所在的位置:网站首页 › python读取数据集中 › 实验三 |
1)读取iris数据集中鸢尾花的萼片,花瓣长度 import pandas as pd import numpy as np df=pd.read_csv("D:\iris.csv") print(df)2)对鸢尾花的萼片,花瓣长度进行排序; df['Sepal.Length']=df['Sepal.Length'].astype(float) df['Sepal.Width']=df['Sepal.Width'].astype(float) df['Petal.Length']=df['Petal.Length'].astype(float) df['Petal.Width']=df['Petal.Width'].astype(float) #对鸢尾花的萼片,花瓣长度进行排序 a=np.sort(df['Sepal.Length']) print(a) b=np.sort(df['Petal.Length']) print(b)3)对鸢尾花的萼片,花瓣长度进行去重; #去除重复值 print('去重后的萼片长度表为:',np.unique(df['Sepal.Length'])) print('去重后的花瓣长度表为:',np.unique(df['Petal.Length']))4)求鸢尾花的萼片,花瓣长度的和,以及累计和; #计算数组总和 print('萼片长度表的总和为:',np.sum(df['Sepal.Length'])) print('花瓣长度表的总和为:',np.sum(df['Petal.Length'])) #计算所有元素的累计和 print('萼片长度表的累计和为:',np.cumsum(df['Sepal.Length'])) print('花瓣长度表的累计和为:',np.cumsum(df['Petal.Length']))5)求鸢尾花的萼片,花瓣长度的均值; #计算数组均值 print('萼片长度表的均值为:',np.mean(df['Sepal.Length'])) print('花瓣长度表的均值为:',np.mean(df['Petal.Length']))6)求鸢尾花的萼片,花瓣长度的标准差、方差; #计算数组标准差 print('萼片长度表的标准差为:',np.std(df['Sepal.Length'])) print('花瓣长度表的标准差为:',np.std(df['Petal.Length'])) #计算数组方差 print('萼片长度表的方差为:',np.var(df['Sepal.Length'])) print('花瓣长度表的方差为:',np.var(df['Petal.Length']))7)求鸢尾花的萼片,花瓣长度的最大值、最小值。 #计算最小值 print('萼片长度表的最小值为:',np.min(df['Sepal.Length'])) print('花瓣长度表的最小值为:',np.min(df['Petal.Length'])) #计算最大值 print('萼片长度表的最大值为:',np.max(df['Sepal.Length'])) print('花瓣长度表的最大值为:',np.max(df['Petal.Length']))
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |