Created
April 11, 2018 13:19
-
-
Save wsvincent/8104abb2be8a3985b8caa72db94c1400 to your computer and use it in GitHub Desktop.
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 csv | |
from school.models import Zipcode | |
def import_us_population(): | |
for csvfile in ( | |
'school_data/us_population_2014.csv', | |
): | |
with open(csvfile, 'rU') as csvinput: | |
reader = csv.reader(csvinput, delimiter=',', quotechar='"',) | |
next(reader) | |
for index, row in enumerate(reader): | |
if row[3] == '-': | |
continue | |
population = row[3].translate(None, '"\+-,') | |
try: | |
zipcode = Zipcode.objects.get( | |
five_digit=row[1] | |
) | |
except Exception, error: | |
# print index, row[1], str(error) | |
continue | |
if zipcode: | |
zipcode.population = population | |
zipcode.save() | |
def run(): | |
import_us_population() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment