I am trying to use geopy.geocoders to map real estate data from Hanoi. I have a list of ~11,000 addresses of sales, I would like to assign latitude and longitude to each address so I can create a map and calculate distances relative to price, etc.
I have run this code on small batches of addresses with no issues, but when I try to scale it to the full column I am getting errors, so I tried to implement a rate limiter, but I am still getting an error after around 500 queries(I think)
What is my next step to troubleshoot this? Are there any alternative libraries or APIs I can use to assign lat/long to addresses? This is my first data viz project so I'm still pretty new to all of this.
This is the code
geolocator = Nominatim(user_agent="hanoi real estate 2020")
def get_lat_long(neighborhood):
location = geolocator.geocode(neighborhood)
return (location.latitude, location.longitude)
from geopy.extra.rate_limiter import RateLimiter
geocode = RateLimiter(geolocator.geocode, min_delay_seconds=1)
data['clean_address'] = data['clean_address'].apply(geocode)
data['clean_address'] = data['clean_address'].apply(lambda loc: tuple(loc.point) if loc else None)
data[['Latitude', 'Longitude']] = data['clean_address'].apply(get_lat_long).apply(pd.Series)
Subreddit
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...