Created
November 14, 2022 19:22
-
-
Save steven-terrana/a231fc4408a25b41c24cded91c13e442 to your computer and use it in GitHub Desktop.
lookup zip codes from addresses
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
# import module | |
from geopy.geocoders import Nominatim | |
import csv | |
import re | |
# initialize Nominatim API | |
geolocator = Nominatim(user_agent="geoapiExercises") | |
filename = 'data.csv' | |
with open(filename, 'r') as csvfile: | |
datareader = csv.reader(csvfile) | |
for row in datareader: | |
street = row[4] | |
city = row[5] | |
state = row[6] | |
if "N/A" in city or "N/A" in state: | |
continue | |
address = f'{street} {city} {state}' | |
location = geolocator.geocode(address) | |
if location: | |
data = location.raw | |
loc_data = data['display_name'] | |
print(loc_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment