I have a list of nested dictionaries in python with data that I want to analyze using pandas. Here's some example data:
[
{
"A": { "left": 1, "right": 2 },
"B": { "left": 3, "right": 4 },
"C": { "left": 5, "right": 6 },
},
{
"A": { "left": 7, "right": 8 },
"B": { "left": 9, "right": 10 },
"C": { "left": 11, "right": 12 },
},
...
]
And so on. As the example shows, each item in the array is a dictionary with the same keys, and each key points to a dictionary with the same keys. In table form, I imagine it should look something like this:
|idx|A |B |C |
| |left|right|left|right|left|right|
--------------------------------------
| 0 | 1| 2| 3| 4| 5| 6|
| 1 | 7| 8| 9| 10| 11| 12|
| 2 | ... |
What I want to do is aggregate the min, mean, and max of "left" and "right" across this list of dictionaries for each letter, so that it ends up with a DataFrame like this:
|idx|left_min|left_mean|left_max|right_min|right_mean|right_max|
----------------------------------------------------------------
| A | 1| 4| 7| 2| 5| 8|
| B | 3| 6| 9| 4| 7| 14|
| C | 5| 8| 11| 6| 9| 12|
I'm experienced with python but relatively new to pandas, so I'm trying to get it right within a pandas framework before I just write it myself in python. I've tried many different ways to mold and shape pandas DataFrames into this form but I can't quite manage it. Every attempt I've made has either multi-indexed in strange ways, or can't aggregate properly. I feel like I'm missing something fundamental here. Any help is appreciated.