-1

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']
Sam
  • 1
  • 1
  • Please provide a [mcve], as well as the current and expected output. – AMC Jul 29 '20 at 18:06
  • Hi there, I have added a screenshot of the code. I tried to use more complex code to see if the results were different, but it keeps giving me wrong coordinates for some borough. I need the correct coordinates as I will need to use this info for a clusterization with Foursquare. – Sam Jul 29 '20 at 18:10
  • _I have added a screenshot of the code_ Please share it as text, not an image. – AMC Jul 29 '20 at 18:11
  • sorry I am new at this, just uploaded the code – Sam Jul 29 '20 at 18:17
  • That's not enough for a [mcve], though. – AMC Jul 29 '20 at 22:26

1 Answers1

0

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() ]
Rusty Widebottom
  • 985
  • 2
  • 5
  • 14