Created
January 30, 2019 15:57
-
-
Save Manoj-nathwani/fb59106ad63acc5c5ec87824da5359bc to your computer and use it in GitHub Desktop.
id,city,country ---> id,lat,lon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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