我已经在熊猫中创建了 MultiIndex 数据框,如下所示:
Aritcle
Feed_Count
HealthDay InfocusRx WhiteCoats Beats
year month s_id
2016 03 12 10 7 8
03 13 15 8 9
04 11 16 15 14
04 10 14 12 13
我想创建json记录:
{
"year": 2016,
"month": 03,
"s_id":12,
"Article":{
"feed_count":{
"HealthDay":10,
"InfocusRx":7,
"Whitecoats Beats":8
}
}
}
我试图重置所有3个级别的索引,但是我无法找到一种将帧转换为特定json结构的方法。
dummy = articleFeedCount.stack(level=[0,1,2]).reset_index()