I have the following dataframe:
key category amount
2019-01 abc 123
2019-01 xyz 111
2019-02 abc 87
2019-02 xyz 34
2019-03 abc 15
2019-04 def 64
How would I go about transforming this data into the below list of dicts. Essentially each dict represents a category along with all dates and corresponding amounts for that category:
[
{
"category": "abc",
"2019-01": 123,
"2019-02": 87,
"2019-03": 15
},
{
"category": "xyz",
"2019-01": 111,
"2019-02": 34
},
{
"category": "def,
"2019-04": 64
}
]