我希望通过将数据下的列更改为dataframe,将API响应更改为dataframe。注意,它还在data (message)下面有一些嵌套参数,我想让它成为单独的列。
{
'success': True,
'code': 200,
'data': [
{
'id': 342964769,
'type': 'ios',
'create_time': 1567591650,
'open_count': 2,
'environment': 'production',
'campaign_id': 12713145,
'project_id': 1758,
'error': 0,
'sent_count': 3,
'message': {
'timestamp': '1567591643',
'badge': '',
'alert': "'I pulled pints and cut turf here back in the day' - Mike Pence speaks to "
"small crowd in Doonbeg",
'sound': 'default',
'articleId': '38465289',
'category': 'news/',
'id': '342964769',
'pushId': 'fireabse-5d6f8cdb8c3e9',
'title': 'Independent.ie',
'content-available': '1',
'xpush': 'yes',
'cid': '12713145'
},
'error_message': None
}, {
'id': 342964771,
'type': 'android',
'create_time': 1567591650,
'open_count': 0,
'environment': 'production',
'campaign_id': 12713145,
'project_id': 1758,
'error': 0,
'sent_count': 0,
'message': None,
'error_message': None
}
]
}发布于 2020-08-21 16:24:14
这就是你想要的?
def dict_pop(d, *args):
v = d.pop(*args)
return v if v else {}
resp = [{**dict_pop(i,'message'), **i} for i in resp['data']]
resp = pd.DataFrame(resp)https://stackoverflow.com/questions/63519222
复制相似问题