问题描述
以下是我的数据示例:
{'Country/Region': {0: nan,1: nan,2: nan,3: nan,4: nan},'Lat': {0: '33.93911',1: '41.1533',2: '28.0339',3: '42.5063',4: '-11.2027'},'Long': {0: '67.709953',1: '20.1683',2: '1.6596',3: '1.5218',4: '17.8739'},'Province/State': {0: nan,4: nan}}
注意:这是一个熊猫数据框,出于询问此问题的目的,我仅将其转换为字典。
这是我尝试过的:
df[['Lat','Long']].apply(lambda x,y : geocoder.osm([x,y],method='reverse'),axis=1)
由此,我收到此错误消息:
TypeError: ("<lambda>() missing 1 required positional argument: 'y'",'occurred at index 0')
解决方法
您的lambda中的
x
将在数据帧中排成一行,这是您需要做的
df.apply(lambda row : geocoder.osm([row['Lat'],row['Long']],method='reverse'),axis=1)
如果您的数据集很大,请考虑使用pandarallel