简体   繁体   中英

Geopy generate wrong coordinates (Lat and Lon)

When I try to look for London' Boroughs coordinates with GEOPY, some of the Boroughs are completely wrong (like Sutton appears in North London when is actually in the South). Also if the data frame where I am taking the information from is sorted by House_Price and not by Boroughs, it generates different coordinates (??.).

Any suggestions?

Thanks a lot!

def get_latilong(postal_code):
lati_long_coords = None
while(lati_long_coords is None):
    g = geocoder.arcgis('{}, London, UK'.format(postal_code))
    lati_long_coords = g.latlng
return lati_long_coords

get_latilong('Sutton')

Borough = df20['Borough']    
coords = [ get_latilong(Borough) for Borough in Borough.tolist() ]

df20_coords = pd.DataFrame(coords, columns=['Latitude', 
'Longitude'])
df20['Latitude'] = df20_coords['Latitude']
df20['Longitude'] = df20_coords['Longitude']

I'm wondering if you are stomping on the value of your variable Borough in your list comprehension. Does it work better if you use a different variable in the for statement?

BEFORE

coords = [ get_latilong(Borough) for Borough in Borough.tolist() ]

AFTER

coords = [ get_latilong(b) for b in Borough.tolist() ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM