【发布时间】:2021-09-19 02:20:00
【问题描述】:
response[0]={'@type': 'g:Vertex',
'@value': {'id': 'account-2199023262994',
'label': 'Account',
'properties': {'account_number': [{'@type': 'g:VertexProperty',
'@value': {'id': {'@type': 'g:Int32',
'@value': 544016139},
'value': '0002-1990-2326-2994',
'label': 'account_number'}}],
'last_name': [{'@type': 'g:VertexProperty',
'@value': {'id': {'@type': 'g:Int32',
'@value': -1616372909},
'value': 'Law-Yone',
'label': 'last_name'}}],
'first_name': [{'@type': 'g:VertexProperty',
'@value': {'id': {'@type': 'g:Int32',
'@value': -451458550},
'value': 'Eric',
'label': 'first_name'}}]}}}
我在列表中有一个嵌套字典,它是另一个嵌套字典的一部分。上面的整个代码 sn-p 本身就是列表response 的一个元素。
我尝试使用以下方法将其展平:
pd.json_normalize(response, meta = ['@type', ['@value', 'id'], ['@value', 'label'], ['@value', 'properties']])
我也期望将字典的内部列表变平。
有人可以帮我吗?我需要遍历数据框还是有任何直接可用的方法?
【问题讨论】:
-
@Ajax1234 我已经编辑了问题,请检查预期输出
标签: python pandas dictionary nested json-normalize