将字典列表转换为 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:
df = pd.DataFrame(d)
注意:这不适用于嵌套数据.
Note: this does not work with nested data.
这篇关于将字典列表转换为 Pandas DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文