I'm using geopy
library to get the latitude and longitude of a list of the location name. So far retrieving data is good but I'm having trouble with appending retrieved data to the end of each row. I tried to use df.append
but the result's not ideal. Can someone tell me how to solve this? Thanks a lot!
THis is my code segment(I want to convert print
part (lat
and lon
) at the end of each row, separately in two new columns, append nothing if lat/lon's value is empty)
for cell in df['Offices']:
cell = pinyin.get(cell, format="strip", delimiter='')
place = str(cell)
geolocator = Nominatim(timeout=3)
location = geolocator.geocode(place)
# print location ip
if location:
print((location.latitude, location.longitude))
print('Converting finished.')
Question Update
I have a dataframe containing columns like "Offices", "Country"..etc. What I want to do is, using geopy
to read in the df["Officies"]
, which is a string of location name and append the output location.latitude, location.longitude
at the end of its corresponding row(aka. create two new columns). I have trouble with appending values.