I am now struggling with writing a dictionary from a csv file.
The format of csv file is like:
student, Test 1, Test 2, Test 3, Final Exam
A, 9, 19, 9, 22
B, 10, 16, 9, 26
C, 11, 17, 8, 27
D, 7, 14, 9, 18
E, 8, 20, 8, 23
weight, 0.15, 0.25, 0.2, 0.4
max_points 12 20 9 30
Where the 2-6 rows are students' names, their test scores on each test. And the last two rows represent weight of each test and full score of each test seperately.
Now, I want to create a dictionary from this list that looks like:
{'Test 1': {'weight': '0.15', 'max_points': '12'},
'Test 2': {'weight': '0.25', 'max_points': '20'},
'Test 3': {'weight': '0.2', 'max_points': '9'},
'Final Exam': {'weight': '0.4', 'max_points': '30'}}
Where the keys are the variables of the first row in the csv file except the variable students; and in each nested dictionary, keys are the names of the first column and last two rows in the csv file: weight, max_points. The corresponding values are just values in their rows respectively.
The only thing I have come up with by now is:
reader = csv.DictReader(open('gradebook.csv'))
for row in reader:
key = row.pop('Student')
And I have no idea about how to proceed. Thank you so much for help!!!