I've got a dictionaries with two nested dictionaries inside. Here is a minimal example :
df = {'line1': {'a': {'a': 1, 'b': 2}, 'b': {'a': 3, 'b': 4}},
'line2': {'a': {'a': 5, 'b': 6}, 'b': {'a': 7, 'b': 8}},
'line3': {'a': {'a': 9, 'b': 10}, 'b': {'a': 11, 'b': 12}},
'line4': {'a': {'a': 13, 'b': 14}, 'b': {'a': 15, 'b': 16}}}
I have hundreds of lines of codes in my program, and this structure seemed to be the easiest to store every data I need. I want to create a pandas dataFrame like this :
aa ab ba bb
line1 1 2 3 4
line2 5 6 7 8
line3 9 10 11 12
line4 13 14 15 16
But it seems that the pd.DataFrame(dict) command do not handles correctly more than 2 nested dictionaries, I got this :
pd.DataFrame(df).T
a b
line1 {u'a': 1, u'b': 2} {u'a': 3, u'b': 4}
line2 {u'a': 5, u'b': 6} {u'a': 7, u'b': 8}
line3 {u'a': 9, u'b': 10} {u'a': 11, u'b': 12}
line4 {u'a': 13, u'b': 14} {u'a': 15, u'b': 16}
Is there an easy way to solve this ? Or do I have to write additional code to transform my dictionary, or worse, to design another way to store my data (that would make me re-write several parts of the program) ?
Thanks in advance.