1

我正在尝试将此geopy对象的输出写入csv文件,但它将每个字母放在不同的列中,并在不同的行上打印纬度和经度。我该如何解决?

我希望能够在不同时间运行此功能并将新地址打印到下一行。保存数据而不是覆盖它。这可以用csvpython写来完成吗?

from geopy.geocoders import Nominatim
import csv

def loc_find(file):
'''
This function take in a user given location and gives back the address with 
city, zip code, state, county and country.
It also provides latitude and longitude.
'''
    geolocator = Nominatim()
    loc_input = raw_input("Add the location you would like data back for: ")
    location = geolocator.geocode(loc_input)
    print(location.address)
    print((location.latitude, location.longitude))

    with open(r"", 'w') as fp:
        a = csv.writer(fp)
        data = location
        a.writerows(data)    
4

1 回答 1

0

好吧,您将单个Location对象作为rows(行对象列表)传递,您应该将其作为单行传递。

代替:

a.writerows(location)

和:

a.writerow(location) 
于 2016-03-09T20:50:48.190 回答