【发布时间】:2016-02-28 22:23:53
【问题描述】:
我有一个 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
]
}
]
我试图进入一个堆叠的 DataFrame,看起来像:
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 对象粘贴到数据框中时,我总是会得到一些变化:
“分数”列是一个列表。我已经搜索了很长时间并努力寻找一个示例,但无法弄清楚如何将列表解压缩为我想要的格式。
建议?
【问题讨论】:
-
除了我的回答之外,this SO answer 似乎可能是相关的。
标签: python json pandas data-analysis