'ID_2',
'ID_3',
'ID_4',
'ID_5',
'ID_6',
'ID_7',
'ID_8',
.)
response={}
u = [response[x] for x in list(b.index)]
KeyError Traceback (most recent call last)
in
1 response={}
----> 2 u = [response[x] for x in tuple(list(b.index))]
in (.0)
1 response={}
----> 2 u = [response[x] for x in tuple(list(b.index))]
KeyError: 'ID_1'
报错是因为response是个空字段,它没有元素,你使用循环的x去取值当然报错喽,你可以使用get方法
response.get(x, None)
response是个空字典,你要做的是赋值,不是取值
你可能是要做赋值操作, 类似操作如下
response={}
u = [response[x]=x for x in list(b.index)]