1+ #!/usr/bin/env python
2+ # -*- coding: utf-8 -*-
3+
4+ """
5+ Cconstruct a zipcode sqlite database for uszipcode extension.
6+ """
7+
8+ from __future__ import print_function
9+ from pprint import pprint as ppt
10+ from sqlite4dummy import *
11+ import pandas as pd
12+
13+ df = pd .read_csv ("zipcode.txt" , sep = "\t " )
14+ engine = Sqlite3Engine ("zipcode.sqlite3" )
15+ metadata = MetaData ()
16+ zipcode_table = Table ("zipcode" , metadata ,
17+ Column ("Zipcode" , dtype .TEXT , primary_key = True ),
18+ Column ("ZipCodeType" , dtype .TEXT ),
19+ Column ("City" , dtype .TEXT ),
20+ Column ("State" , dtype .TEXT ),
21+ Column ("POPULATION" , dtype .INTEGER ),
22+ Column ("Density" , dtype .REAL ),
23+ Column ("TotalWages" , dtype .REAL ),
24+ Column ("Wealthy" , dtype .REAL ),
25+ Column ("HouseOfUnits" , dtype .INTEGER ),
26+ Column ("LandArea" , dtype .REAL ),
27+ Column ("WaterArea" , dtype .REAL ),
28+ Column ("Latitude" , dtype .REAL ),
29+ Column ("Longitude" , dtype .REAL ),
30+ Column ("NEBoundLatitude" , dtype .REAL ),
31+ Column ("NEBoundLongitude" , dtype .REAL ),
32+ Column ("SWBoundLatitude" , dtype .REAL ),
33+ Column ("SWBoundLongitude" , dtype .REAL ),
34+ )
35+ metadata .create_all (engine )
36+ engine .insert_many_record (zipcode_table .insert (), df .values .tolist ())
37+ engine .commit ()
0 commit comments