【发布时间】:2021-11-11 17:54:59
【问题描述】:
我有一个 JSON 文件如下:
{
"ALPHA": [
{
"date": "2021-06-22",
"constituents": {
"BBB": 0,
"EEE": 1,
"BTB": 1,
"YUY": 1
}
},
{
"date": "2021-09-07",
"constituents": {
"BBB": 0,
"EEE": 0,
"BTB": 0,
"YUY": 0
}
}
],
"BETA": [
{
"date": "2021-06-22",
"constituents": {
"BBB": 1,
"EEE": 1,
"BTB": 1,
"YUY": 1
}
},
{
"date": "2021-09-07",
"constituents": {
"BBB": 1,
"EEE": 1,
"BTB": 1,
"YUY": 1
}
}
],
"THETA": [
{
"date": "2021-06-22",
"constituents": {
"BBB": 0,
"EEE": 1,
"BTB": 1,
"YUY": 0
}
},
{
"date": "2021-08-20",
"constituents": {
"BBB": 0,
"EEE": 1,
"BTB": 1,
"YUY": 0
}
},
{
"date": "2021-09-07",
"constituents": {
"BBB": 0,
"EEE": 1,
"BTB": 1,
"YUY": 0
}
}
]
}
我想将上面的内容读入一个熊猫数据框,其中第一个索引是日期,第二个索引是第一个键(即“ALPHA”、“BETA”、“THETA”),列是内部键(即“BBB”、“EEE”、“BTB”、“YUY”),单元格值就是这些内键的值。
如何从 JSON 文件将其读入 pandas?
【问题讨论】: