I have a pandas dataframe displaying users' performance on test questions. It looks like this:
userID questionID correct
-------------------------------
1 1 1
1 5 1
1 6 0
1 8 0
1 10 1
2 3 1
2 5 1
2 6 0
. . .
. . .
. . .
I want to make a feature vector for each user saying whether or not they got each question right, that looks something like this:
questionID 1 2 3 4 5 6 ...
userID -------------------------------------------------
1 1 NaN NaN NaN 1 0 ...
2 NaN NaN 1 NaN 1 0 ...
. ...
. ...
.
Each user only gets shown a subset of all the questions, so it's a sparse matrix.
How can I make the above table in pandas?
I wanted to do something like below - grouping by userID and questionID and then unstacking, but I'm not sure exactly how it should work.
df = df.groupby(['user_id','question_id'])
df.unstack()
Thanks for your help.