Skip to content

Instantly share code, notes, and snippets.

@Manoj-nathwani
Created January 30, 2019 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Manoj-nathwani/fb59106ad63acc5c5ec87824da5359bc to your computer and use it in GitHub Desktop.
Save Manoj-nathwani/fb59106ad63acc5c5ec87824da5359bc to your computer and use it in GitHub Desktop.
id,city,country ---> id,lat,lon
# -*- coding: utf-8 -*-
import csv, os, time
from geopy.geocoders import Nominatim
THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
my_file = os.path.join(THIS_FOLDER, 'data.csv')
geolocator = Nominatim()
with open(my_file, 'r') as csvFile:
reader = csv.reader(csvFile)
for row in reader:
time.sleep(1.5)
location = ', '.join([row[1], row[2]])
location = geolocator.geocode(location)
if location:
lat,lon = str(location.latitude), str(location.longitude)
else:
lat,lon = '', ''
print(','.join([
row[0],
lat,
lon
]))
csvFile.close()
#print(location.address)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment