Хотелось бы иметь координаты в соответствующих столбцах.
Это мой df["Boroughs"]
0 Beaches-East York
1 Davenport
2 Eglinton-Lawrence
3 Etobicoke Centre
4 Etobicoke North
5 Humber River-Black Creek
6 Parkdale-High Park
7 Scarborough-Agincourt
8 Scarborough-Rouge Park
9 Toronto-Danforth
10 Willowdale
11 York Centre
Name: Boroughs, dtype: object
Мои шаги:
dfB = []
city = 'Toronto, Canada'
boroughs = df["Boroughs"]
for borough in boroughs:
try:
address = borough + ', ' + city
geolocator = Nominatim(user_agent="foursquare_agent")
location = geolocator.geocode(address)
lat = location.latitude
lng = location.longitude
dfB.append([location, lat, lng])
except Exception as e:
print(address, lat, lng)
dfB = pd.DataFrame(dfB, columns=["location", "lat", "lng"])
dfB
Выход: Как можноУдалить дополнительную информацию и координаты из столбца местоположения?
location lat lng
0 (Beaches—East York, Old Toronto, Toronto, Golden Horseshoe, Ontario, Canada, (43.6814698, -79.3060214)) 43.681470 -79.306021
1 (Davenport, Old Toronto, Toronto, Golden Horseshoe, Ontario, Canada, (43.6715614, -79.4482927)) 43.671561 -79.448293
2 (Eglinton—Lawrence, North York, Toronto, Golden Horseshoe, Ontario, Canada, (43.7192647, -79.429765)) 43.719265 -79.429765
3 (Etobicoke Centre, Etobicoke, Toronto, Ontario, Canada, (43.6798327, -79.5389927)) 43.679833 -79.538993
4 (Etobicoke North, Etobicoke, Toronto, Ontario, Canada, (43.7410925, -79.5892249)) 43.741093 -79.589225
5 (Humber River—Black Creek, North York, Toronto, Ontario, Canada, (43.7337368, -79.5382285)) 43.733737 -79.538229
6 (Parkdale—High Park, Old Toronto, Toronto, Golden Horseshoe, Ontario, Canada, (43.6499649, -79.473014)) 43.649965 -79.473014
7 (Scarborough—Agincourt, Scarborough, Toronto, Ontario, Canada, (43.797221, -79.3083901035784)) 43.797221 -79.308390
8 (Scarborough—Rouge Park, Scarborough, Toronto, Ontario, Canada, (43.80292335, -79.175434369733)) 43.802923 -79.175434
9 (Toronto—Danforth, Old Toronto, Toronto, Golden Horseshoe, Ontario, Canada, (43.6789439, -79.3448597)) 43.678944 -79.344860
10 (Willowdale, North York, Toronto, Ontario, Canada, (43.7753558, -79.4166859823926)) 43.775356 -79.416686
11 (York Centre, North York, Toronto, Golden Horseshoe, Ontario, Canada, (43.750241, -79.463352)) 43.750241 -79.463352
Ожидаемый результат:
location lat lng
0 Beaches—East York 43.681470 -79.306021
1 Davenport 43.671561 -79.448293
2 Eglinton—Lawrence 43.719265 -79.429765
3 Etobicoke Centre. 43.679833 -79.538993
.....