MertcanGokgoz

city district

Dec 30th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. from openpyxl import load_workbook
  2.  
  3. wb = load_workbook(filename='../Data/12_04_2017.xlsx')
  4. ws = wb.active
  5.  
  6. sql = open('../Data/CityDistrict.sql', 'a')
  7.  
  8. regions = {}
  9. for index, row in enumerate(ws.rows):
  10.     if index == 0:
  11.         continue
  12.  
  13.     index_str = str(index + 1)
  14.  
  15.     city = ws["A" + index_str].value
  16.     district = ws["B" + index_str].value
  17.  
  18.     if city not in regions:
  19.         regions[city] = {}
  20.  
  21.     if district not in regions[city]:
  22.         regions[city][district] = {}
  23.  
  24. for city in regions.keys():
  25.     city_name = city.title()
  26.  
  27.     for district in regions[city].keys():
  28.         district_name = district.title()
  29.         for data in len(district):
  30.             x = 'INSERT INTO "District" ("Province_id", "District") VALUES (%s, %s);\n' % (, district_name)
  31.             sql.write(x)
  32. sql.close()
Add Comment
Please, Sign In to add comment