gpt4 book ai didi

python - 属性错误 : 'list' object has no attribute 'keys' when attempting to create DataFrame from list of dicts

转载 作者:太空宇宙 更新时间:2023-11-03 14:14:10 25 4
gpt4 key购买 nike

非常感谢您的帮助,

我有一个字典列表,需要放入数据框中。我知道 Pandas 的正常方法是

final_df=pd.DataFrame.from_records(Mixed_and_Poured[0], index='year')

其中 Mixed_and_poured 是一个列表,其中包含另一个实际包含字典的列表

print Mixed_and_Poured
[[{'Country': 'Brazil', u'Internet users': '2.9', 'Year': '2000'}, {'Country': 'Brazil', u'Internet users': '21', 'Year': '2005'}, {'Country': 'Brazil', u'Internet users': '40.7', 'Year': '2010'}, {'Country': 'Brazil', u'Internet users': '45', 'Year': '2011'},

我可以发誓

final_df=pd.DataFrame.from_records(Mixed_and_Poured[0], index='year')

刚刚工作!!但是当我今天运行它时它抛出

AttributeError: 'list' object has no attribute 'keys'

为什么现在要在此列表中查找键?

最佳答案

事实证明,我实际上并没有在一个只有字典的列表上操作,那里的末尾隐藏着一个小 SCSS 列表。

对不起你们!

关于python - 属性错误 : 'list' object has no attribute 'keys' when attempting to create DataFrame from list of dicts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34831448/

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