I am looking for any advice on how to cleanly convert a python multi level nested dictionary (from JSON) into a data frame boolean table.
Rules:
- Only True is recorded. If empty it is False.
- The list may be of N Length
- The groups may be of N length
- The bools may be of N types
Example Input:
{1:{'group_a':{'bool_a':True,
'bool_b':True,
'bool_n':True},
'group_n':{'bool_b':True,
'bool_n':True}
},
2:{'group_a':{'bool_a':True,
'bool_b':True,
'bool_n':True},
'group_n':{'bool_b':True,
'bool_n':True}
},
'n':{'group_a':{'bool_a':True,
'bool_c':True},
'group_n':{'bool_b':True}
},
}
Desired Output:
Ga_Ba, Ga_Bb, Ga_Bc, Ga_Bn, Gn_Ba, Gn_Bb, ... Gn_Bn....
1 True True False True False True True
2 True True False True False True True
n True False True False False False False
...
Ideas? Bonus points for speed and conciseness. I have a solution but I am looking for something more elegant than the for loop mess I have now. Alternative data structures may also be welcome.