【发布时间】:2017-05-05 10:16:26
【问题描述】:
我正在处理一个 JSON 响应,其格式类似于下面的多嵌套字典:
{u'addresses': [],
u'application_ids': [20855193],
u'applications': [{u'answers': [{u'answer': u'Indeed ',
u'question': u'How did you hear?'}],
u'applied_at': u'2015-10-29T22:19:04.925Z',
u'candidate_id': 9999999,
u'credited_to': None,
u'current_stage': {u'id': 9999999,
u'name': u'Application Review'},
u'id': 9999999,
u'jobs': [{u'id': 9999999,u'name': u'ENGINEER'}],
u'last_activity_at': u'2015-10-29T22:19:04.767Z',
u'prospect': False,
u'rejected_at': None,
u'rejection_details': None,
u'rejection_reason': None,
u'source': {u'id': 7, u'public_name': u'Indeed'},
u'status': u'active'}],
u'attachments': [{u'filename': u'Jason_Bourne.pdf',
u'type': u'resume',
u'url': u'https://resumeURL'}],
u'company': None,
u'coordinator': {u'employee_id': None,
u'id': 9999999,
u'name': u'Batman_Robin'},
u'email_addresses': [{u'type': u'personal',
u'value': u'jasonbourne@gmail.com'}],
u'first_name': u'Jason',
u'id': 9999999,
u'last_activity': u'2015-10-29T22:19:04.767Z',
u'last_name': u'Bourne',
u'website_addresses': []}
我正在尝试将 JSON 扁平化为表格,并在 pandas 文档中找到以下示例:
http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.io.json.json_normalize.html
据我了解,“record_path”参数指定了您感兴趣的最低级别记录的路径。“record_path”参数只能是字符串,或字符串列表。但是,要调用上面数据中的“答案”记录,我必须指定字符串 和 索引,如下所示;
answer = data['applications'][0]['answers']['answer']
question = data['applications'][0]['answers']['question']
如何将上面的记录路径作为参数输入到 json_normalize 函数中?
谢谢!
【问题讨论】: