将字典列表转换为pandas DataFrame [英] Convert list of dictionaries to a pandas DataFrame
本文介绍了将字典列表转换为pandas DataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的词典列表:
I have a list of dictionaries like this:
[{'points': 50, 'time': '5:00', 'year': 2010},
{'points': 25, 'time': '6:00', 'month': "february"},
{'points':90, 'time': '9:00', 'month': 'january'},
{'points_h1':20, 'month': 'june'}]
我想像这样把它变成熊猫DataFrame
:
And I want to turn this into a pandas DataFrame
like this:
month points points_h1 time year
0 NaN 50 NaN 5:00 2010
1 february 25 NaN 6:00 NaN
2 january 90 NaN 9:00 NaN
3 june NaN 20 NaN NaN
注意:列的顺序无关紧要.
Note: Order of the columns does not matter.
如何将字典列表转换为如上所述的pandas DataFrame?
How can I turn the list of dictionaries into a pandas DataFrame as shown above?
推荐答案
假设d
是您的字典列表,简单地:
Supposing d
is your list of dicts, simply:
pd.DataFrame(d)
这篇关于将字典列表转换为pandas DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文