done w/complete single item dataframe conversion using json and pandas

This commit is contained in:
spbeach46 2020-10-03 22:19:01 -07:00
parent 21804923a5
commit 116dcfcdd6

View File

@ -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)