gpt4 book ai didi

python - 将字典列表转换为 pandas DataFrame

转载 作者:IT老高 更新时间:2023-10-28 12:01:59 26 4
gpt4 key购买 nike

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

注意:列的顺序无关紧要。

最佳答案

如果 dsdicts 的列表:

df = pd.DataFrame(ds)

注意:这不适用于嵌套数据。

关于python - 将字典列表转换为 pandas DataFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20638006/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com