How to use python to form nested json data?

problem description

Fields of the database:

uid,  year,   quarter,   score
 1    2018         4
 1    2018         3
 1    2018         3
 2    2017         5

credits are counted on a quarterly basis, so points for a quarter need to be summed up.
the key of the first layer is uid, the key of the second layer is the year, the key of the third layer is the quarter, and the value is the integral and

.
s={1:{2018:{1:7,3:3}},2:{2017:{2:5}}}

the environmental background of the problems and what methods you have tried

I use json, but it is difficult to operate.

use the two-dimensional array
a = [1 br 2018, 1], [1, 2018, 1, 4], [2, 2017, 1, 7], [2, 2018, 2, 7]

when a [I] [0] = = a [j] [0] & a [I] [1] = = a [j] [1] & & a [I] [2] = a [j] [2]

ss=sum(a[i][3])


manipulate a two-dimensional array

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

forms this three-layer nested json, or other well-structured format.

Mar.28,2021

Don't you try pandas ?

In [4]: df.groupby(['quarter','uid','year']).sum()
Out[4]:
                  
quarter   uid  year  score
    1   2018      7
    1   2018      3
    2   2017      5
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bee848-31bfc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bee848-31bfc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?