0
我有一個JSON文件看起來像:JSON堆疊數據幀
[
{
"id" : "abc",
"mood" : "happy",
"scores" : [
10,
15,
20
]
},
{
"id" : "def",
"mood" : "happy",
"scores" : [
103,
150,
200
]
},
{
"id" : "ghi",
"mood" : "sad",
"scores" : [
1,
15,
20,
45,
600,
1400
]
},
{
"id" : "jkl",
"mood" : "sad",
"scores" : [
10,
100,
1000,
10000
]
}
]
我敢試圖得到了多層數據幀,看起來像:
id mood score
0 abc happy 10
1 abc happy 15
2 abc happy 20
3 def happy 103
...
14 jkl sad 10
15 jkl sad 100
等
但是,當我將JSON對象粘貼到數據框中時,我總是會得到一些變化:
其中「分數」列是列表。我已經搜索了很長時間,很難找到一個例子,但無法弄清楚如何將列表解壓縮到我想要的格式。
對此提出建議?
除了我的回答,[這個蘇答案(http://stackoverflow.com/questions/21160134/flatten-a -column-with-value-of-type-list-while-duplicating-the-other-columns-va)似乎可能是相關的。 – jme