-1
votes

I would like to convert nested dict to DataFrame object. I have a dictionary:

{
'David X': {
            'something1': 'string1'
            'something2': 'string2'
            'something3': 'string3'
            },
'David Y': {
            'something1': 'str1'
            'something2': 'str2'
            'something3': 'str3'
            }
}

I would like to obtain DataFrame object with rows consist of names, columns consist of 'something {1,2,3}' and appropriate values.

1

1 Answers

2
votes

Use DataFrame.from_dict:

df = pd.DataFrame.from_dict(d, orient='index')
print (df)
        something1 something2 something3
David X    string1    string2    string3
David Y       str1       str2       str3