here is my csv code:
and I am going to calculate the mean of every list in csv and add the name and mean to the csv file.
Quote:mandana,5,7,3,15
hamid,3,9,4,20,9,1,8,16,0,5,2,4,7,2,1
sina,19,10,19,6,8,14,3
sara,0,5,20,14
soheila,13,2,5,1,3,10,12,4,13,17,7,7
ali,1,9
sarvin,0,16,16,13,19,2,17,8
and I am going to calculate the mean of every list in csv and add the name and mean to the csv file.
import csv from statistics import mean import csv from statistics import mean with open ('grades.csv', 'r') as input_file_name: reader=csv.reader(input_file_name) lastrow=[] for row in reader: #print (row) name = row[0] these_grades=list() for grade in row[1:]: #print(grade) these_grades.append(int(grade)) #print(name,grade,these_grades) print(name, mean(these_grades)) with open('grades.csv', 'w', newline='') as output_file_name: writer = csv.writer(output_file_name) writer.writerows(name ) writer.writerows(mean )