예제 #1
0
파일: io_data.py 프로젝트: rkawauchi/IHK
 def _import_gsp_file(self, input_file, year_span='2011-12'):
     reader = csv.DictReader(input_file)
     headers = reader.next()
     for row in reader:
         #we only care about the GSP (Gross State Product)
         #which is mislabeled as GSDP 
         if not row['Sector'] == 'GSDP (2004-05 Prices)':
             continue
         state_name = util.clean_state_name(row['State Name'])
         gsp = row[year_span]
         #add the gsp information to the relevant State
         for state in self.states:
             if state.name == state_name and state.classification == 'total':
                 state.gsp = gsp
예제 #2
0
파일: io_data.py 프로젝트: rkawauchi/IHK
 def _import_mpce_file(self, input_file, mpce_type, classification):
     #http://www.blog.pythonlibrary.org/2014/02/26/python-101-reading-and-writing-csv-files/
     reader = csv.reader(input_file)
     for row in reader:
         #The first row is just the headers, so we skip it 
         if row[0] == 'state':
             continue
         #remove extra spaces around each element in the row
         row = [value.strip() for value in row]
         row[0] = util.clean_state_name(row[0])
         #Create a Mpce object - makes things easier to insert
         #This is not a very efficient method, but it works
         mpce = Mpce(mpce_type, classification, *row)
         #add the row to the mpce table
         insert = Mpce.__table__.insert()
         self.connection.execute(insert, mpce.__dict__)