Last active
July 18, 2016 18:24
-
-
Save osya/41d57377729cd1b95b85 to your computer and use it in GitHub Desktop.
Example of using openpyxl & geopy #geopy #openpyxl
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 sys | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
from geopy.geocoders import Yandex | |
from openpyxl import load_workbook | |
filename = 'realty.xlsx' | |
wb = load_workbook(filename) | |
ws = wb.get_sheet_by_name('data') | |
geolocator = Yandex() | |
iterrows = ws.iter_rows() | |
next(iterrows) | |
for i,row in enumerate(iterrows): | |
cell = row[2] | |
location = geolocator.geocode(cell.value) | |
AdministrativeArea = location.raw['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country']['AdministrativeArea']['AdministrativeAreaName'] | |
row[1].value = AdministrativeArea | |
wb.save(filename) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment