我已經提到這一點: Nested Json to pandas DataFrame with specific format轉換JSON到csv使用python熊貓
這:json_normalize produces confusing KeyError
嘗試和規範的json代碼片段中使用熊貓json_normalize。 但是,輸出未完全正常化。下面是我的代碼片段
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
[{'value': {'share': 2, 'like': 10}}]
我會一直喜歡有兩個列輸出,而不是像
value.share value.like
2 10
我應該如何做到這一點?
這如果你解釋爲什麼你的代碼可以工作會更好。 –