Reputation: 21
I have a DF that looks something like this:
studentId | startime | skill | correct | timetaken | questionid |
---|---|---|---|---|---|
1 | 109670354 | Algebra | 0 | 23 | 22 |
2 | 109670232 | Statistics | 1 | 55 | 5679 |
1 | 109670111 | Algebra | 1 | 8 | 10111 |
Now I want to transform this into a JSON that would look something like this:
Note sequence can be any random number for time being
{ "Type": "XXX", "studentId": 1, "timestamp": "1631858259", "data": { "activity_data": [ { "sequence": 1, "question_id": 1, "correct": 1, "elapsed_time": 9641 }, {
"sequence": 2,
"question_id": 2,
"correct": 0,
"elapsed_time": 10454
},
{
"sequence": 3,
"question_id": 3,
"correct": 0,
"elapsed_time": 10454
},
{
"sequence": 4,
"question_id": 4,
"correct": 0,
"elapsed_time": 10454
},
{
"sequence": 5,
"question_id": 5,
"correct": 0,
"elapsed_time": 10454
}
]
}
}
Note that how apart from studentId, all other columns per student fall under activity data, this is the expected outcome I'm trying to get. So essentially for each student I want to retrieve activity data, which would be the rest of the columns. I understand using a groupby function a solution could be found.
Upvotes: 0
Views: 26