From 116dcfcdd6330609e2dbd101ac968513aeed9f00 Mon Sep 17 00:00:00 2001 From: spbeach46 Date: Sat, 3 Oct 2020 22:19:01 -0700 Subject: [PATCH] done w/complete single item dataframe conversion using json and pandas --- shopping_test.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/shopping_test.py b/shopping_test.py index 862bccf..904d5a4 100644 --- a/shopping_test.py +++ b/shopping_test.py @@ -5,23 +5,23 @@ import pandas as pd params = { "callname":"GetMultipleItems", - "appid":"scottbea-xlister-PRD-6796e0ff6-14862949", + "appid":"scottbea-xlister-PRD-6796e0ff6-14862949", "version":"671", "responseencoding":"JSON", "ItemID":'184228756721', # you pass in a list? If not then maybe a comma-separated "IncludeSelector":"ItemSpecifics", } -response = requests.get("https://open.api.ebay.com/shopping?", params=params) # +response = requests.get("https://open.api.ebay.com/shopping?", params=params) data = response.json() pretty_data = json.dumps(data, indent=2) -df = pd.read_json(data, 'Item') -nvl = df.iloc[0]['ItemSpecifics.NameValueList'] -nvl_dict = {} -for item in nvl: - nvl['Name'] -# departments = ["3034","93427"] -# Best plan of action is probably json-->pandas df. You can decide how to clean later, but it -# will prolly be easier if you clean in pandas because you can drop columns easily that you don't -# need. Figure out how to "flatten" your json data into the df first. +names = [] +values = [] +nvl = data['Item'][0]['ItemSpecifics']['NameValueList'] +for nvl_dict in nvl: + names.append(nvl_dict['Name']) + values.append(nvl_dict['Value']) +nvl_dict = dict(zip(names, values)) +data.update(nvl_dict) +