【发布时间】:2016-11-15 18:56:33
【问题描述】:
我正在尝试从我的 pandas 数据框中的纬度和经度点获取国家/地区名称。 目前我已经使用 geolocator.reverse(latitude,longitude) 来获取地理位置的完整地址。但是没有选项可以从完整地址中检索国家名称,因为它返回一个列表。
使用方法:
def get_country(row):
pos = str(row['StartLat']) + ', ' + str(row['StartLong'])
locations = geolocator.reverse(pos)
return locations
通过传递数据框调用 get_country:
df4['country'] = df4.apply(lambda row: get_country(row), axis = 1)
当前输出:
StartLat StartLong Address
52.509669 13.376294 Potsdamer Platz, Mitte, Berlin, Deutschland, Europe
只是想知道当我们通过地理点时是否有一些 Python 库来检索国家。
任何帮助将不胜感激。
【问题讨论】:
-
你不能拆分地址并从列表中获取元素 - 即。
"Potsdamer Platz, Mitte, Berlin, Deutschland, Europ".split(", ")[-2] -
你用什么模块?
-
@furas:我目前使用 geolocator.reverse()
-
我没有要求函数名,而是模块名 -
geopy,geocoder,其他。但我看到你得到了答案。 -
你能把初始化
geolocator的代码贴出来吗?