将字典列表转换为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

      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,如上所示?

回答:

假设d是您的列表,只需:

pd.DataFrame(d)

 
 
Code问答: http://codewenda.com/topics/python/
Stackoverflow: Convert list of dictionaries to Dataframe

*转载请注明本文链接以及stackoverflow的英文链接

发表评论

电子邮件地址不会被公开。 必填项已用*标注

− 3 = 1