[python] 將字典列表轉換為Dataframe



Answers

在熊貓16.2中,我必須做pd.DataFrame.from_records(d)才能使其工作。

Question

我有這樣的字典列表:

[{'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

注意:列的順序無關緊要。

最終目標是將其寫入文本文件,這似乎是我能找到的最佳解決方案。 如何將字典列表變成如上所示的熊貓數據框?




Related