从嵌套字典到DataFrame [英] From nested dict to DataFrame
本文介绍了从嵌套字典到DataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将嵌套字典转换为DataFrame对象.我有一本字典:
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'
}
}
我想获得DataFrame对象,其行由名称组成,列由"{1,2,3}"组成,并具有适当的值.
I would like to obtain DataFrame object with rows consist of names, columns consist of 'something {1,2,3}' and appropriate values.
推荐答案
使用 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
这篇关于从嵌套字典到DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文