多次元の辞書をパンダのデータフレームに変換するのにあなたの助けが必要です。私はAPI呼び出し(Shopify)から取得するJSONファイルからdictを取得します。APIコール - 多次元のネストされた辞書からパンダのデータフレーム
response = requests.get("URL", auth=("ID","KEY"))
data = json.loads(response.text)
次のように「データ」の辞書にはなります。この場合、
{'orders': [{'created_at': '2016-09-20T22:04:49+02:00',
'email': '[email protected]',
'id': 4314127108,
'line_items': [{'destination_location':
{'address1': 'Teststreet 12',
'address2': '',
'city': 'Berlin',
'country_code': 'DE',
'id': 2383331012,
'name': 'Test Test',
'zip': '10117'},
'gift_card': False,
'name': 'Blueberry Cup'}]
}]}
辞書は4つの寸法を持っていると私はパンダのデータフレームに辞書を変換したいと思います。私はjson_normalize()からpandas.DataFrame.from_dict()までのすべてを試していましたが、どこにでもいられませんでした。 dictをdfに変換しようとすると、リストのリストを含む列が取得されます。
誰かにアプローチする方法はありますか? EDITED
おかげ
:
あなたは@piRSquaredありがとうございます。あなたのソリューションは正常に動作します!しかし、注文に別の製品があった場合にそれを解決する方法は?それはうまくいくからです。 2つの製品と注文のJSON応答は以下の通りである(目標は同じ「のcreated_at」を有する第2の行を有することである「メール」などの列):
{'orders': [{'created_at': '2016-09-20T22:04:49+02:00',
'email': '[email protected]',
'id': 4314127108,
'line_items': [{'destination_location':
{'address1': 'Teststreet 12',
'address2': '',
'city': 'Berlin',
'country_code': 'DE',
'id': 2383331012,
'name': 'Test Test',
'zip': '10117'},
'gift_card': False,
'name': 'Blueberry Cup'},
{'destination_location':
{'address1': 'Teststreet 12',
'address2': '',
'city': 'Berlin',
'country_code': 'DE',
'id': 2383331012,
'name': 'Test Test',
'zip': '10117'},
'gift_card': False,
'name': 'Strawberry Cup'}]
}]}
だから最終的にはDFがオンでなければなりませんすべての販売された製品の行ごとの基準。ありがとう、本当にありがとう!
私はあなたが別の顔を持っていることができればクールになる、上記の私の質問を編集しました! –