Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from openpyxl import load_workbook
- wb = load_workbook(filename='../Data/12_04_2017.xlsx')
- ws = wb.active
- sql = open('../Data/CityDistrict.sql', 'a')
- regions = {}
- for index, row in enumerate(ws.rows):
- if index == 0:
- continue
- index_str = str(index + 1)
- city = ws["A" + index_str].value
- district = ws["B" + index_str].value
- if city not in regions:
- regions[city] = {}
- if district not in regions[city]:
- regions[city][district] = {}
- for city in regions.keys():
- city_name = city.title()
- for district in regions[city].keys():
- district_name = district.title()
- for data in len(district):
- x = 'INSERT INTO "District" ("Province_id", "District") VALUES (%s, %s);\n' % (, district_name)
- sql.write(x)
- sql.close()
Add Comment
Please, Sign In to add comment