我想從我的熊貓數據框中獲取緯度和經度點的國家名稱。 目前我使用geolocator.reverse(緯度,經度)來獲取地理位置的完整地址。但沒有選項可以從完整地址中檢索國家名稱,因爲它會返回一個列表。從Python中的地理位置檢索國家
方法使用:
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庫檢索我們通過地理點的國家。
任何幫助,將不勝感激。
你不能分割地址並從列表元素 - 即。 ''波茨坦廣場,米特,柏林,德國,歐洲「.split(」,「)[ - 2]' – furas
你使用什麼模塊? – furas
@furas:我當前使用geolocator.reverse() – user3447653