I have a multi-index dataframe like below:
2019-01-08 2019-01-15 2019-01-22 2019-01-29 2019-02-05
6392 height 3 6 5 3 3
length 3 3 5 9 3
6393
height 1 6 1 4 3
length 5 3 2 3 3
I would like to convert it to JSON similar to below.
{
"6392": {
"2019-01-08": [{
"height": 3
"length": 3
}],
"2019-01-15": [{
"height":
"length": 3
}],
"2019-012-22": [{
"height": 5
"length": 5
}],
...
},
"6393": {
"2019-01-08": [{
"height": 1
"length": 5
}],
"2019-01-15": [{
"height": 6
"length": 3
}],
"2019-012-22": [{
"height": 1
"length": 2
}],
...
}
I've tried something like df.to_json(orient='index') which returns an error. And using reset_index() doesn't return the hierarchies I want!
Thanks for the help.
[{...}]for each date? IMHO, it's redundant wrapping list over a single element (dict).