Although a few other examples of nested JSON to pandas dataframe can be found, this one I cannot find and hence not succeed. I have a nested JSON as follows:
{'x':
{'1':[2,5,6],'2':[7,6]},
'y':
{'1':[0,4,8],'2':[8,1]},
'z':
{'1':[8,0,9],'2':[2,2]}}
and I would like a dataframe as:
1_0 1_1 1_2 2_0 2_1
x 2 5 6 7 6
y 0 4 8 8 1
z 8 0 9 2 2
the labelling of the columns do not necessarily have to be exactly this as long as I can infer the data correctly.
I have tried this:
import json
import pandas as pd
from pandas.io.json import json_normalize
with gzip.open('example.json') as f:
d = json.load(f)
df = pd.json_normalize(d)
df
resulting in this:
