Python Flatten Multiply嵌套字典JSON与Pandas

时间:2016-12-20 08:56:39

标签: python json pandas nested

我正在处理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函数的参数?

谢谢!

1 个答案:

答案 0 :(得分:3)

我认为您可以使用(function setCanvas() { var canvas = document.getElementsByClassName("canvas"); var x = 250; var y = 250; // set width and height of canvas canvas[0].setAttribute("style", "height:" + x + "px;" + " width:" + y + "px;"); console.log("canvas width " + y); console.log("canvas height " + x); }()); 嵌套record_path

list