Python Pandas: Convert nested dictionary to dataframe -


i have dic this:

{1 : {'tp': 26, 'fp': 112}, 2 : {'tp': 26, 'fp': 91}, 3 : {'tp': 23, 'fp': 74}} 

and convert in dataframe this:

t tp fp 1 26  112 2 26  91 3 23  74 

does know how?

try dataframe.from_dict() , keyword argument orient 'index' -

example -

in [20]: d = {1 : {'tp': 26, 'fp': 112},    ....: 2 : {'tp': 26, 'fp': 91},    ....: 3 : {'tp': 23, 'fp': 74}}  in [24]: df =pd.dataframe.from_dict(d,orient='index')  in [25]: df out[25]:    tp   fp 1  26  112 2  26   91 3  23   74 

if want set column name index column , use - df.index.name , example -

in [30]: df.index.name = 't'  in [31]: df out[31]:    tp   fp t 1  26  112 2  26   91 3  23   74 

Comments