geopy python package: unified wrapper to API providers

https://github.com/geopy/geopy

The geopy package provides a unified access to many geocoding API providers, as well as a wrapper to geocode addresses without explicitly managing HTTP requests.

Most geocoding API providers require an account and/or an API key to associate the API calls to a particular account. Nominatim is a provider that provides a few API calls for free.

from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="professor_data_science_project")
location = geolocator.geocode("175 5th Avenue NYC, USA")
location
Location(Flatiron Building, 175, 5th Avenue, Flatiron District, Manhattan Community Board 5, Manhattan, New York County, City of New York, New York, 10010, United States, (40.741059199999995, -73.98964162240998, 0.0))

Example: getting latitude, longitude information for penguins’ islands

import seaborn as sns
penguins = sns.load_dataset('penguins')
penguins.island.unique()
array(['Torgersen', 'Biscoe', 'Dream'], dtype=object)
geo_information =[
    geolocator.geocode(island + ' island')
    for island in penguins.island.unique()
]
geo_information
[Location(Torgersen Island, (-64.7727428, -64.07460782690988, 0.0)),
 Location(Biscoe Islands, (-65.8925785, -66.440456, 0.0)),
 Location(Dream Island, Hunterston, Shire of Wellington, Victoria, Australia, (-38.658885999999995, 146.8513695741931, 0.0))]
geo_information[0]
Location(Torgersen Island, (-64.7727428, -64.07460782690988, 0.0))
geo_information[0].latitude
-64.7727428
geo_information[0].longitude
-64.07460782690988