从嵌套字典到DataFrame

时间:2019-03-02 08:29:48

标签: python pandas dataframe dictionary

我想将嵌套字典转换为DataFrame对象。我有一本字典:

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

我想获得DataFrame对象,其中行包含名称,列包含“ {1,2,3}”和适当的值。

1 个答案:

答案 0 :(得分:2)

使用DataFrame.from_dict

Variable Name      Values 
Variable 1           =  ( 2, 4) , ( 5, 1)           
Variable 2            =   ( 7, 4) , ( 1, 3)           
Variable 3            =   ( 5, 7) , ( 5, 1)           
Variable 4            =   ( 2, 4) , ( 2, 1)             
Variable 5            =   ( 9, 8) , ( 2, 4)           
Variable 6            =   ( 3, 4) , ( 5, 7)           
Variable 7            =   ( 4, 7) , ( 4, 2)           
Variable 8           =   ( 5, 4) , ( 5, 7)
Etc….    
(This data will be stored on server.) 

Now for example user give input variable 1, 4, 5, 7
The calculator will show result =( 2, 4).