【发布时间】:2020-12-20 21:11:01
【问题描述】:
有没有办法将这种 JSON 响应导入 Pandas?我一直试图让它与 json_normalize 一起使用,但我似乎一次无法获得超过一个级别的工作(我可以得到笔记但不能在 custom_fields 中)。我也无法弄清楚如何调用 ['reporter']['name'] 之类的东西(应该是 jdoe)。这是来自 Mantis 及其请求响应的 JSON 输出。我现在想知道是否需要将其分解为多个帧并重新组合在一起,还是应该使用 for 循环并将我想要的数据放入更好的格式以供 PD 导入?
在我的脑海中,每个项目都应该是系列中的一列,都像这样与 id 列相关联。
id | summary | project.name | reporter.name ..|.. custom.fields.Project_Stage | ... notes1.reporter.name | notes1.text ... notes2.reporter.name | notes2.text
{
"issues": [
{
"id": 1234,
"summary": "Some text",
"project": {
"id": 1,
"name": "North America"
},
"category": {
"id": 11,
"name": "Retail"
},
"reporter": {
"id": 1099,
"name": "jdoe"
},
"custom_fields": [
{
"field": {
"id": 107,
"name": "Product Escalations"
},
"value": ""
},
{
"field": {
"id": 1,
"name": "Project_Stage"
},
"value": "Pending"
}
],
"notes": [
{
"id": 214288,
"reporter": {
"id": 9999,
"name": "jdoe"
},
"text": "Worked with Mark over e-mail",
"view_state": {
"id": 10,
"name": "public",
"label": "public"
},
"type": "note",
"created_at": "2020-12-04T15:55:02-08:00",
"updated_at": "2020-12-04T15:55:02-08:00"
},
{
"id": 214289,
"reporter": {
"id": 9999,
"name": "jdoe"
},
"text": "I attempted on numerous occasions to setup a meeting with him to set it up for him.",
"view_state": {
"id": 10,
"name": "public",
"label": "public"
},
"type": "note",
"created_at": "2020-12-04T15:57:02-08:00",
"updated_at": "2020-12-04T15:57:02-08:00"
}
]
}
]
}
这就是我脑海中 DF 的样子。一条线/系列一张票的所有数据。
【问题讨论】:
-
请发布您预期输出的数据框
-
最好的方法是@sammywemmy?
-
创建一个表格,可能是excel或记事本,其中包含每行的标题和值。复制并粘贴到您的问题中。它将指导 SO 人适当地回答您的问题,并消除猜测
标签: python python-3.x pandas dataframe