将词典列表转换为Dataframe [英] Convert list of dictionaries to Dataframe
本文介绍了将词典列表转换为Dataframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的字典列表:
[{'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.
最终,目标是将其写入文本文件,这似乎是最好的我可以找到解决方案如何将字典列表转换成熊猫DataFrame,如上所示?
Ultimately, the goal is to write this to a text file and this seems like the best solution I could find. How can I turn the list of dictionaries into a panda DataFrame as shown above?
推荐答案
假设 d
是你的列表,只是:
Supposing d
is your list of dicts, simply:
pd.DataFrame(d)
这篇关于将词典列表转换为Dataframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文