我使用的是python 3.6版本,出现以下错误:
TypeError: an integer is required (invsf['Destn Branch'] = invsf.apply(lambda x: convloc(x['Destn Branch'])))
代码:
loclist = ['Destn Branch','Hub SC Location','Origin Branch']
maplist = dict({'MAAG': 'MAAC','NEIR': 'GAUB','RJPR': 'PTLF','SIKM': 'SILB','KLMF':'COKB','AMDE':'AMDO'})
print (loclist)
totalconsinv = len(invsf)
## Check done
def convloc(location):
get_dict = maplist.get(location)
print ('get_dict',get_dict)
if get_dict is None:
#print 'location',location
return location
else:
return get_dict
invsf['Destn Branch'] = invsf.apply(lambda x: convloc(x['Destn Branch']))
如何修复此错误?你知道吗
几点提示:
{...}
声明了一个dict。在上面调用dict()
是多余的。你知道吗如果apply操作只影响一列,则应该对该序列调用apply。你知道吗
这将允许您摆脱
lambda
。但是,在您的情况下,调用
map
更合适。你知道吗相关问题 更多 >
编程相关推荐