I have a csv file storing the number of times students have attempted each question, which has the format as below
UserID Q1 Q2 Q3 Q4
20 1 2 3 1
21 0 1 2 1
I am trying to write a python program to store the data into an array attempts_count.
attempts_count = numpy.zeros(shape=(2000,200,200))
with open('Question_Attempts_Worksheet_1.csv' , 'r') as csvfile:
csvfile.readline() # skip the first line(column title)
for line in csvfile:
csv_row = line.split()
user_id = csv_row[0]
for question_counter in range(0,4):
attempts_count[user_id][1][question_counter] += csv_row[question_counter + 1]
I expect to obtain attempts_count[20][1][0]=1, attempts_count[20][1][2]=3, etc.
However, I got an error message saying
"IndexError: only integers, slices (
:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices".
May I know how should I fix the problem?
csvmodule? It automatically parses your CSV file and allows you to access individual rows and columns without the need to manually parse rows and split by separators.