【发布时间】:2017-09-12 05:42:44
【问题描述】:
我已经提到了这个: Nested Json to pandas DataFrame with specific format
还有这个:json_normalize produces confusing KeyError
尝试在 pandas 中使用 json_normalize 规范化我的 json sn-p。 但是,输出并没有完全标准化。这是我的代码的 sn-p
x =[{'fb_metrics': [{'period': 'lifetime', 'values': [{'value': {'share': 2, 'like': 10}}], 'title': 'Lifetime Post Stories by action type', 'name': 'post_stories_by_action_type', '_id': '222530618111374_403476513350116/insights/post_stories_by_action_type/lifetime', 'description': 'Lifetime: The number of stories created about your Page post, by action type. (Total Count)'}]}]
df = pd.io.json.json_normalize(x[0]['fb_metrics'])
values 列的输出是
values
[{'value': {'share': 2, 'like': 10}}]
我希望有两列输出,而不是像
value.share value.like
2 10
我应该如何做到这一点?
【问题讨论】:
标签: python json csv pandas dataframe