1

I'm trying to associate the city/country/state name to the latitude and longitude of my dataset. This is how I made it:

import pandas as pd
import io
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="geoapiExercises")

def city_state_country(row):
    coord = f"{row['latitude']}, {row['longitude']}"
    location = geolocator.reverse(coord, exactly_one=True)
    address = location.raw['address']
    city = address.get('city', '')
    state = address.get('state', '')
    country = address.get('country', '')
    row['city'] = city
    row['state'] = state
    row['country'] = country
    return row

ddf_slice= ddf_slice.apply(city_state_country, axis=1)

but I have so many rows and it takes forever. how can I solve this?

Progman
  • 16,827
  • 6
  • 33
  • 48

1 Answers1

0

I have the same experience. We are using an API that is throttled and distributed. To avoid a timeout try

location = geolocator.reverse(coord, exactly_one=True, timeout=None)