I want to convert my dataframe to a json string. If I simply do df.to_json(orient='records')
, then it's converted well. However, I want to make several transformations in the json string.
This is my dataframe df
:
df =
GROUP HOUR AVG_MINUTES AVG_GRADE
AAA 7 67 5.5
AAA 8 58 6.5
AAA 9 55 4.5
BBB 7 15 5.1
BBB 8 18 5.4
CCC 9 34 5.5
The json string should look as follows:
[
{
"GROUP":"AAA",
"AVG_MINUTES":[[7,67],[8,58],[9,55]],
"AVG_GRADE":[[7,5.5],[8,6.5],[9,4.5]]
},
{
"GROUP":"BBB",
"AVG_MINUTES":[[7,15],[8,18],[9,34]],
"AVG_GRADE":[[7,5.1],[8,5.4],[9,5.5]]
}
]
I want to get HOUR
values inside each pair in AVG_MINUTES
and AVG_GRADE
. Is it possible to do? Or should I do it manually? (it would be a bad news, since the dataframe is quite big)