【发布时间】:2020-08-10 21:43:00
【问题描述】:
我想从我的数据框中位置的纬度和经度中提取国家名称。
这是我的数据示例:
{'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, 1: nan, 2: nan, 3: nan, 4: nan}}
注意:这是一个 pandas 数据框,我只是为了提出这个问题而将其转换为字典。
这是我尝试过的:
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 应该使用 2 个参数?
-
df[['Lat','Long']].apply(lambda x,y : geocoder.osm([x,y], method='reverse'), axis=1)? -
@QuangHoang 用你的建议编辑了我的答案,仍然收到类似的错误
-
@SuperStormer 感谢您注意到这一点,已编辑问题
-
您需要阅读
apply的文档并对您对其工作方式的假设进行一些基本测试。