I am trying to turn a dictionary of the following type:
{'123': [ {'feature_1':'a1','feature_2':'b1,...},{'feature_1':'a2','feature_2':'b2,...},...,{'feature_1':'an','feature_2':'bn} ],... } to a pandas DataFrame.
My best attempt looks like this:
df = pd.DataFrame.from_dict({(key, lis_index, sub_key): data[key][lis_index][sub_key]
for key in data.keys()
for lis_index in range(len(data[key]))
for sub_key in data[key][lis_index].keys()},
orient='index')
where data is my dictionary. However, this leaves 2 columns, one of which a triplet and the other one is a value column. I want to turn it in the following format:
key feature_1 feature_2 ... feature_n
123 a1 b1 z1
123 a2. b2. z2
... ... ... ...
123 an bn zn