I am trying to create columns for the geolocation of countries from a CSV.
So far I am able to create a new column with both latitude
and longitude
by mapping over the columns and applying the geolocate()
function.
Dataframe
geolocation
(-34.9964963, -64.9672817)
Expected output:
geolocation latitude longitude
(-34.9964963, -64.9672817) -34.9964963 -64.9672817
I am mapping over the the columns so I am not sure how to get just the latitude and longitude and make their respective columns.
def add_geolocation(df, country_column):
df["geolocation"] = country_column.map(lambda x: geolocate(x))
return df
add_geolocation(df=df, country_column=df["country"])
In the function geolocate()
I return both of them.
def geolocate(country):
# Location
loc = geolocator.geocode(country, timeout=10000)
# Latitiude
lat = get_latitude(loc)
# Longitude
long_ = get_longitude(loc)
# Address
add = get_address(loc)
return lat, long_
Would it be possible for me to specify in the lambda function that I want to just use the latitude.
For example, latitude, longitude = geolocate(country)
then just use the values latitude.