1
扁平化JSON文件中的数据,我想扁平化复杂的嵌套JSON文件使用。请找到下面的示例JSON数据使用熊猫正规化
{
"applications": [
{
"id": 87334412,
"name": "cdata1",
"language": "known",
"health_status": "unknown",
"reporting": true,
"last_reported_at": "2017-10-06T06:30:55+00:00",
"application_summary": {
"response_time": 1.2,
"throughput": 216,
"error_rate": 0,
"target": 0.5,
"ascore": 1,
"host_count": 3,
"instance_count": 3
},
"settings": {
"column": 0.5,
"columns": 7,
"columns1": true,
"columns2": false
},
"links": {
"application_data": [
93818199,
93819351,
93819359
],
"servers": [],
"application_content": [
32006189,
87342924,
47565225
]
}
},
代码:
import json
from pandas.io.json import json_normalize
json_file=open('ptr1.json')
json_data=json.load(json_file)
#print json_data["applications"]
for line in json_data:
data=json_normalize(line,['name','id'])
print data
任何一个可以帮助获取以下数据名称,id,last_reported_at,instance_count。注JSON文件包含了很多细节的id
谢谢你,它的工作如预期 –
@prasannaKumar,欢迎您!请考虑[接受](http://meta.stackexchange.com/a/5235)/ [upvoting](https://meta.stackexchange.com/questions/173399/how-to-upvote-on-stack-overflow )一个答案,如果你认为它已经回答了你的问题 – MaxU