How do I take addresses and generate lat, long coordinates from them in python? I have a few addresses that I would like get lat, long points but seems it doesn't work.
I used geopandas but it returns me nothing. I am also a bit confused about what to use for the user_agent. Here is my code,
import pandas as pd
from geopy.geocoders import Nominatim
df2['location_lat'] = ""
df2['location_long'] = ""
geolocator = Nominatim(user_agent="myApp")
for i in df2.index:
try:
#tries fetch address from geopy
location = geolocator.geocode(df2['Location'][i])
#append lat/long to column using dataframe location
df2.loc[i,'location_lat'] = location.latitude
df2.loc[i,'location_long'] = location.longitude
except:
#catches exception for the case where no value is returned
#appends null value to column
df2.loc[i,'location_lat'] = ""
df2.loc[i,'location_long'] = ""
Any help is appreciated. Thanks.