3
我正在使用Facebook Python SDK查询Insights端点,并且很难做出响应我使用Python和随后的大熊猫工作。我做以下电话:如何解析来自Python SDK的嵌套FB API响应
account = AdAccount('act_id')
params = {
'fields': [Insights.Field.impressions,Insights.Field.clicks,Insights.Field.actions,Insights.Field.spend],
'breakdowns': [Insights.Breakdown.hourly_stats_aggregated_by_advertiser_time_zone],
'time_range': {
'since': 'start',
'until': 'end',
},
'action_attribution_windows': ['7d_click'],
}
result = account.get_insights(params=params)
print (result)
返回像这样的数据:
[<Insights> {
"actions": [
{
"7d_click": 600,
"action_type": "custom_event_xyz",
"value": 50
},
{
"7d_click": 600,
....
}
],
"clicks": 1500,
"date_start": "start",
"date_stop": "end",
"hourly_stats_aggregated_by_advertiser_time_zone": "00:00:00 - 00:59:59",
"impressions": "60000",
"spend": 60
}, <Insights> {
....
]
,而把不包括actionsdata成大熊猫数据帧中的数据,我不管理正确扁平化的操作数据,以便聚合级别是一致的(即“操作”键为列标题)。通过在线检查并在Stackoverflow上进行检查,使用python加载json并相应地处理它以及使用pandas读取它们都是不起作用的选项。
总结我没有看到我可以如何优雅地挖掘响应的深层嵌套部分,并轻松地使内容与其他内容兼容。