我试图将此geopy
对象的输出写入csv
文件,但它会将每个字母放在不同的列中,并在不同的行上打印纬度和经度。我该如何解决这个问题?
我希望能够在不同时间运行此功能并将新地址打印到下一行。保存数据不会覆盖它。可以在python中编写csv
来完成吗?
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)