0

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.

  • It sounds like you want to organize the data by student (studentId)? If so, I would first construct an intermediate data structure (DF) for each student, and produce the JSON from that. – Bill Packard Sep 20 '22 at 12:42
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 20 '22 at 18:28

0 Answers0