I have a DataFrame
with Lat/Long coordinates in separate series. I am trying to use GeoPy and Nominatim to get the reverse raw address. I keep getting errors such as:
TypeError: reverse() takes 2 positional arguments but 3 were given
or
needs coordinate pair or Point
Here is some sample data as a test DataFrame:
Id Latitude Longitude
1 30.197535 -97.662015
2 34.895699 -82.218903
3 33.6367 -84.428101
4 33.6367 -84.428101
5 32.733601 -117.19
and here is my code:
# summarize travelers by country using geopy geocoder
# initialize Nominatim API
geolocator = Nominatim(user_agent="http")
#check the dtypes, they're float
test.dtypes
# combine lat/long into new column
test['geom'] = (test["Latitude"].map(str) + ',' + test['Longitude'].map(str)
check first record
test['geom'][0]
# alternative approach #1
test['geom'] = test['Latitude'].apply(str) + "," + test['Longitude'].apply(str)
test['geom'][0]
# reverse geocode
test['address'] = geolocator.reverse(test['Latitude'],test['Longitude']).raw
What am I doing wrong? I am new to this and it is infuriating. All examples I've found don't work or only show geocoding with one record.
Examples:
-
https://towardsdatascience.com/reverse-geocoding-in-python-a915acf29eb6 (<–Can't get RateLimiter portion to work).
Best Answer
Here the Nominatim geocoder (free to choose) from the GeoPy geocoding Python library was used, for more details, please check the documentation.
Coordinates of point features should be passed as a pair (see this thread for more details), otherwise, you may get this error:
Therefore
from geopy.point import Point
was additionally imported.The code below also uses the
vectorize
of NumPy.will result in: