I am downloading some data from BestBuy Products API using python's Requests library and I want to store them into pandas dataframe.
Something like that:
results = requests.get(url1,
params={'paramStuff'},
headers={'User-Agent': ua})
products = json.loads(results.text)
A get a lot of various fields with service info, thus I aim only for specific field in JSON which I want:
products['products']
I have:
[{'details':[{'name': 'Name of Feature', 'value':'Value Of Feature'},
{'name': 'Name of Other Feature', 'value':'Value Of Other
Feature'}, ...],
'ProductId': 'Id Of Product 1',
'Some Other Field': 'Some Other Field Value'},
{same structure as above for other product}, {etc}]
So as you see it is something like a list of dictionaries which in turn contain lists of dictionaries themselves. To highlight - details dict can have various list of combinations of Name: Value (names are different across products as well).
Any idea on how to approach such structure to get into dataframe with such format:
+-----------+-------------------+-------------------+-------------------+------------------+
| ProductID | Name of Feature 1 | Name of Feature 2 | Name Of Feature 3 | Some Other Field |
+-----------+-------------------+-------------------+-------------------+------------------+
| Product 1 | Value | NULL | Value | Value |
| Product 2 | NULL | Value | Value | Value |
+-----------+-------------------+-------------------+-------------------+------------------+
So far I only managed to get to something like this:
+-----------+-----------------------------------------------------------------------------------------------------------------------------------+------------------+
| ProductID | Details | Some Other Field |
+-----------+-----------------------------------------------------------------------------------------------------------------------------------+------------------+
| Product 1 | [{'name': 'Name of Feature', 'value':'Value Of Feature'},{'name': 'Name of Other Feature', 'value':'Value Of Other Feature'},...] | Value 1 |
| Product 2 | [{'name': 'Name of Feature', 'value':'Value Of Feature'},{'name': 'Name of Other Feature', 'value':'Value Of Other Feature'},...] | Value 2 |
+-----------+-----------------------------------------------------------------------------------------------------------------------------------+------------------+