Untitled
unknown
python
a year ago
716 B
8
Indexable
import csv
def createStatDict(file_name="study_performance.csv"):
performanceDict, finalDict = {}, {}
'''open the csv, read the csv, reader contains rows with the data'''
with open(file_name, mode='r') as file:
reader = csv.reader(file, delimiter=',')
'''traversing every row with data in csv'''
for row in reader:
if row[2] not in performanceDict:
performanceDict[row[2]] = [0, 0]
elif row[2] in performanceDict:
performanceDict[row[2]][0] += row[5]
performanceDict[row[2]][1] += 1
for key in performanceDict.keys():
finalDict[key] = performanceDict[key][0] / performanceDict[key][1]
return finalDict
createStatDict("study_performance.csv")Editor is loading...
Leave a Comment