Iterating through a dictionary datatype column within an API response

  dataframe, dictionary, python-3.x

I’m using Python 3.9 to parse through an API response where the values of one of the keys (products) is of dict type. I need to loop through the values of the ‘product’ key.

Example:

[{'id': 78456, 'item': '48-20213', 'product': {'id': 21438274735, 'supplier_part_number': '14109', 'color': 'Green’},'stats': None}] 

Here’s what I’ve tried so far:

df = pd.DataFrame(r.json())

final_df = df[['product']]

how can I use final_df to iterate through the values? I’m trying to get the value of ‘supplier_part_number’.

Source: Python-3x Questions

LEAVE A COMMENT