【发布时间】:2019-05-18 12:02:20
【问题描述】:
我正在尝试从以下字典中提取名称:
df = df[[x.get('Name') for x in df['Contact']]]
下面是我的 Dataframe 的样子:
data = [{'emp_id': 101,
'name': {'Name': 'Kevin',
'attributes': {'type': 'Contact',
'url': '/services/data/v38.0/sobjects/Contact/00985300000bt4HEG4'}}},
{'emp_id': 102,
'name': {'Name': 'Scott',
'attributes': {'type': 'Contact',
'url': '/services/data/v38.0/sobjects/Contact/00985300000yr5UTR9'}}}]
df = pd.DataFrame(data)
df
emp_id name
0 101 {'Name': 'Kevin', 'attributes': {'type': 'Cont...
1 102 {'Name': 'Scott', 'attributes': {'type': 'Cont...
我收到一个错误:
AttributeError: 'NoneType' object has no attribute 'get'
【问题讨论】:
-
你的问题是什么?
-
@njzk2,我正在尝试提取与“名称”对应的值
-
如果这是一个数据框,请提供minimal reproducible example。
-
@coldspeed,对不起,我已经用 Dataframe 的样子更新了我的初始帖子..
-
当前代码的结果是什么?
标签: python python-3.x pandas dictionary dataframe