Pandas 从键值对生成数据帧
我有一个包含键值对的字典列表,我想从中创建一个数据帧,我认为Pandas 从键值对生成数据帧,pandas,Pandas,我有一个包含键值对的字典列表,我想从中创建一个数据帧,我认为from_items()方法将是最简单的方法,但该属性似乎不存在。我抛出错误的方法有什么错误?有没有更好的方法 AttributeError: 'DataFrame' object has no attribute 'from_items' 字典(col\u vals): 代码: IIUC,你有: ldicts = [{'id': 'people5', 'title': 'Stakeholder', 'text': '',
from_items()
方法将是最简单的方法,但该属性似乎不存在。我抛出错误的方法有什么错误?有没有更好的方法
AttributeError: 'DataFrame' object has no attribute 'from_items'
字典(col\u vals
):
代码:
IIUC,你有:
ldicts = [{'id': 'people5',
'title': 'Stakeholder',
'text': '',
'type': 'multiple-person',
'value': None
},
{'id': 'people5',
'title': 'Stakeholder',
'text': 'Test',
'type': 'multiple-person',
'value': 'Michael'
}]
您可以像这样使用pd.DataFrame构造函数:
df = pd.DataFrame(ldicts)
df
输出:
id title text type value
0 people5 Stakeholder multiple-person None
1 people5 Stakeholder Test multiple-person Michael
df = pd.DataFrame(ldicts)
df
id title text type value
0 people5 Stakeholder multiple-person None
1 people5 Stakeholder Test multiple-person Michael