我有一个大的嵌套json对象,我想读入pandas数据帧。json对象内部有许多嵌套的json对。基本分层是:
示例如下:
{
"per_page": 50,
"total": 4,
"data": [
{
"total_time": 5276,
"href": "https://somelink.com",
"custom_variables": {},
"ip_address": "XXX.XXX.XX.XX",
"id": "1111111",
"logic_path": {},
"date_modified": "2018-08-17T19:57:43+00:00",
"response_status": "completed",
"custom_value": "",
"analyze_url": "https://somelink.com/respondent_id=1111111",
"pages": [
{
"id": "38638937",
"questions": []
},
{
"id": "38638938",
"questions": [
{
"id": "124810659",
"answers": [
{
"text": "some_answer_text"
}
]
},
{
"id": "124810660",
"answers": [
{
"text": "some_other_answer_text"
}
]
}
]
},
{
"id": "38638944",
"questions": [
{
"id": "124810656",
"answers": [
{
"col_id": "905794209",
"choice_id": "905794459",
"row_id": "905794204"
},
{
"col_id": "905794210",
"choice_id": "905794463",
"row_id": "905794204"
},
{
"col_id": "905794209",
"choice_id": "905794459",
"row_id": "905794205"
},
{
"col_id": "905794210",
"choice_id": "905794464",
"row_id": "905794205"
}
]
}
]
}
.
.
.
.
.
.
.
.
],
"page_path": [],
"recipient_id": "4107168056",
"collector_id": "216279750",
"date_created": "2018-09-05T15:28:38+00:00",
"survey_id": "222222222",
"collection_mode": "default",
"edit_url": "https://www.somelink.com/somerefnumber",
"metadata": {
"contact": {
"email": {
"type": "string",
"value": "name@somememail.com"
}
}
}
},
{
"total_time": 6978,
"href": "https://somelink.com",
"custom_variables": {},
"ip_address": "XXX.XXX.XX.XX",
"id": "4444444",
"logic_path": {},
"date_modified": "2018-08-15T19:16:43+00:00",
"response_status": "completed",
"custom_value": "",
"analyze_url": "https://somelink.com/respondent_id=4444444",
"pages": [
.
.
.
]
}
],
"page": 1,
"links": {
"self": "https://api.somelink.com/22222222/responses/bulk?page=1&per_page=50"
}
}
一个页面中可以有任意数量的回答、页面和问题。在
我的问题是: 如何将上面的json放入如下所示的pandas datafame中:
我试过使用json_normalize,但我相信我犯了一些错误。在
^{pr2}$作为附加信息,这是来自SurveyMonkey API。SurveyMonkey允许您export survey results to csv via the web interface,但我想使用API重新创建标准响应报告,并最终生成自定义报告/执行其他操作。在
我用的是Python3.6。我假设我需要做一些预处理来整理数据,但我不知道如何做。谢谢任何帮助!在
将json转换为dataframe:
之后:
^{pr2}$相关问题 更多 >
编程相关推荐