又得到徒弟的求救,让我帮他做作业,现在的大学生到底是怎么了??? Python这门课,学起来挺有意思的,自己咋不学着敲代码呢?老是来让我帮 你写,那就再写一次吧,帮你写个作业没问题,看完答案给个赞啊要记得! 答案源码: 复制拿走, 留下你的赞 !!! 谢谢。。。 注:在此提醒各大学生,复制拿走之后修改一下里面的变量什么的,至少把一些名字改了吧,要不然你们班太多学生拿了这答案怕你们老师发现雷同就不好了呢~ 其实是收到粉丝的求助,要我写这题的答案,我就找我徒弟要了题目。来帮你们完成。import csv import numpy as np fileN = 'C:\Users\HP\Desktop\iris.csv' with open(fileN,'r') as FileN: reader = csv.DictReader(FileN) Sepal1 = [row['Sepal.Length'] for row in reader] Sepal_1 = [] for col1 in Sepal1: Sepal_1.append(float(col1)) FileN.close() print(np.mean(Sepal_1)) with open(fileN, 'r') as FileN: reader = csv.DictReader(FileN) Sepal2 = [row['Sepal.Width'] for row in reader] Sepal_2 = [] for col2 in Sepal2: Sepal_2.append(float(col2)) FileN.close() print(np.mean(Sepal_2)) with open(fileN, 'r') as FileN: reader = csv.DictReader(FileN) Petal1 = [row['Petal.Length'] for row in reader] Petal_1 = [] for col3 in Petal1: Petal_1.append(float(col3)) FileN.close() print(np.mean(Petal_1)) with open(fileN, 'r') as FileN: reader = csv.DictReader(FileN) Petal2 = [row['Petal.Width'] for row in reader] Petal_2 = [] for col4 in Petal2: Petal_2.append(float(col4)) FileN.close() print(np.mean(Petal_2)) with open(fileN, 'r') as FileN: reader = csv.DictReader(FileN) iris1 = [iris_item for iris_item in reader] file_name = 'C:\Users\HP\Desktop\my_iris.csv' my_key = [] for i in iris1[0].keys(): my_key.append(i) with open(file_name, 'w', newline = '') as f: write_csv = csv.DictWriter(f, my_key) write_csv.writeheader() write_csv.writerows(iris1) csvFile = open("C:\Users\HP\Desktop\my_iris.csv", "a") fileheader = ["Sepal.Length平均值"] dict_writer = csv.DictWriter(csvFile, fileheader) dict_writer.writerow(dict(zip(fileheader, fileheader))) dict_writer.writerow({"Sepal.Length平均值": np.mean(Sepal_1)}) fileheader = ["Sepal.Width平均值"] dict_writer = csv.DictWriter(csvFile, fileheader) dict_writer.writerow(dict(zip(fileheader, fileheader))) dict_writer.writerow({"Sepal.Width平均值": np.mean(Sepal_2)}) fileheader = ["Petal.Length平均值"] dict_writer = csv.DictWriter(csvFile, fileheader) dict_writer.writerow(dict(zip(fileheader, fileheader))) dict_writer.writerow({"Petal.Length平均值": np.mean(Petal_1)}) fileheader = ["Petal.Width平均值"] dict_writer = csv.DictWriter(csvFile, fileheader) dict_writer.writerow(dict(zip(fileheader, fileheader))) dict_writer.writerow({"Petal.Width平均值": np.mean(Petal_2)}) csvFile.close()
欢迎关注公众号【夜来疏影】
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算