【发布时间】:2016-04-22 05:59:53
【问题描述】:
非常感谢您的帮助,
我有一个需要放入数据框中的字典列表。我知道 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'
为什么现在要在这个列表中寻找键?
【问题讨论】:
-
我正在倾注this related question put 无法弄清楚我的解决方案有什么问题
-
你需要另一个
[0]吗?显然它需要一本字典。 -
使用 pandas 0.16.2 和 Python 3.4,我得到了一个很好的数据框 if 我将
index更正为'Year'(注意大写)并删除了尾随逗号来自Mixed_and_Poured并添加两个右括号]]。
标签: python list dictionary pandas dataframe