Geocoder in python takes too much time to run

Viewed 196

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?

0 Answers
Related