# 8.8:  DataFrame from embedded JSON.  Look at the typical output of an Alphavantage API query,
# which contains a dict of dicts "embedded" within a larger JSON struct (this is saved in a local
# file is called alphavantage_5min.json).  "Drill down" to the dict of dicts by using a subscript,
# and assign the dod by itself to a variable.  Then read the dict of dicts object into a DataFrame
# using pd.DataFrame.from_dict() function, with orient='index'.

import pandas as pd
import json


fname = '../alphavantage_5min.json'

fh = open(fname)

obj = json.load(fh)

dod = obj['Time Series (5min)']

df = pd.DataFrame.from_dict(dod, orient='index')

print(df)

