I have 1000 rows of answers that belong to 200 students for 5 questions. I do not have student ID data so I would like to assign them manually.
Question Answer Student ID
1 2 1
2 2 1
3 88 1
4 4 1
5 7 1
1 2 2
2 2 2
3 85 2
4 3 2
5 7 2
. . .
. . .
. . .
I would like to automatically assign incremental values for every 5 rows for Student ID column.
I am trying this loop where if the value of 5 rows before the current row is the same as the value trying to assign, do +1 and continue to the end. But it is yielding error. What can I do to fix so I can yield student ID for every 5 questions?
I would greatly appreciate your help.
i = 1
data['Student_ID'] = 1
for i, row in data.iterrows():
if row['Student ID'].shift(-4) == i:
row['Student ID'] += i
else:
row['Student ID'] == i
```