0

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.

demid
  • 348
  • 5
  • 16
  • 1
    Your question seems like you want the lat & long nicely formatted to the screen, but you say you want them `append`ed to something. So it's not clear to me. Would it be possible to clarify your question? – Kingsley Oct 22 '18 at 03:26
  • @Kingsley Hi thanks for ur response. Just updated the question. (And why I have `print` in my code is I want to check if `geopy` is working properly, which is. This is the part I wanna update to `appending`) – demid Oct 22 '18 at 03:39

0 Answers0