I want to transfer a nested dic to a dataframe. (The dataframe should not be nested, only the highest layer from the dic should be converted to a dataframe).
dic = {'Key1':
{'Key1_1': [],
'Key1_2':
{'Key1_2_1':
{'Key1_2_1_1': 'value1_2_1_1'},
'Key1_2_2': ['listelement1value1_2_2']}},
'Key2': 'value2',
'Key3': 'value3',
'Key4': 'value4'}
with
df = pd.DataFrame(dic, index=[0])
i get:
+----+--------+--------+--------+--------+
| | Key1 | Key2 | Key3 | Key4 |
|----+--------+--------+--------+--------|
| 0 | nan | value2 | value3 | value4 |
+----+--------+--------+--------+--------+
with
series = pd.Series(dic)
df = series.to_frame().T
+----+----------------------------------------------------------------------------------------------------------------+--------+--------+--------+
| | Key1 | Key2 | Key3 | Key4 |
|----+----------------------------------------------------------------------------------------------------------------+--------+--------+--------|
| 0 | {'Key1_1': [], 'Key1_2': {'Key1_2_1': {'Key1_2_1_1': 'value1_2_1_1'}, 'Key1_2_2': ['listelement1value1_2_2']}} | value2 | value3 | value4 |
+----+----------------------------------------------------------------------------------------------------------------+--------+--------+--------+
and the second result is that what i want. Is there a better way to get the second result without using a series first ?