我很好奇如何使用pandas来读取以下结构的嵌套json:
{
"number": "",
"date": "01.10.2016",
"name": "R 3932",
"locations": [
{
"depTimeDiffMin": "0",
"name": "Spital am Pyhrn Bahnhof",
"arrTime": "",
"depTime": "06:32",
"platform": "2",
"stationIdx": "0",
"arrTimeDiffMin": "",
"track": "R 3932"
},
{
"depTimeDiffMin": "0",
"name": "Windischgarsten Bahnhof",
"arrTime": "06:37",
"depTime": "06:40",
"platform": "2",
"stationIdx": "1",
"arrTimeDiffMin": "1",
"track": ""
},
{
"depTimeDiffMin": "",
"name": "Linz/Donau Hbf",
"arrTime": "08:24",
"depTime": "",
"platform": "1A-B",
"stationIdx": "22",
"arrTimeDiffMin": "1",
"track": ""
}
]
}
Run Code Online (Sandbox Code Playgroud)
这里将数组保持为json.我宁愿把它扩展成列.
pd.read_json("/myJson.json", orient='records')
Run Code Online (Sandbox Code Playgroud)
谢谢你的第一个答案.我应该改进我的问题:数组中嵌套属性的扁平化不是强制性的.只需[A,B,C]连接df.locations ['name']即可.
我的文件包含多个JSON对象(每行1个)我想保留数字,日期,名称和位置列.但是,我需要加入这些地点. …