Skip to content

Instantly share code, notes, and snippets.

@wsvincent
Created April 11, 2018 13:19
Show Gist options
  • Save wsvincent/8104abb2be8a3985b8caa72db94c1400 to your computer and use it in GitHub Desktop.
Save wsvincent/8104abb2be8a3985b8caa72db94c1400 to your computer and use it in GitHub Desktop.
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