我正在寻找一种更有效的方法来填充我的表格,而不是使用[xx在范围xx中]并向表中添加新行。电子表格有数千行,因此需要很长时间。
import openpyxl
import sqlite3
wb=openpyxl.load_workbook('GlobalLandTemperaturesByCountry.xlsx')
print(wb.get_sheet_names())
#GlobalLandTemperaturesByCountry
sheet = wb.get_sheet_by_name('GlobalLandTemperaturesByCountry')
print(sheet.max_row)
#577463 rows
wb2=openpyxl.load_workbook('GlobalLandTemperaturesByState.xlsx')
print(wb2.get_sheet_names())
#GlobalLandTemperaturesByState
sheet2 = wb2.get_sheet_by_name('GlobalLandTemperaturesByState')
print(sheet2.max_row)
#645676 rows
wb3=openpyxl.load_workbook('GlobalLandTemperaturesByMajorCity.xlsx')
print(wb3.get_sheet_names())
#GlobalLandTemperaturesByMajorCi
sheet3 = wb3.get_sheet_by_name('GlobalLandTemperaturesByMajorCi')
print(sheet3.max_row)
#239178 rows
connection = sqlite3.connect('temperature.db')
cursor = connection.cursor()
cursor.execute('''CREATE TABLE Countries
(Date DATE, AverageTemperature REAL, AverageTemperatureUncertainty REAL, Country TEXT)
''')
cursor.execute('''CREATE TABLE States
(Date DATE, AverageTemperature REAL, AverageTemperatureUncertainty REAL, State TEXT, Country TEXT)
''')
cursor.execute('''CREATE TABLE Towns
(Date DATE, AverageTemperature REAL, AverageTemperatureUncertainty REAL, City TEXT, Country TEXT, Latitude REAL, Longitude REAL)
''')
谢谢,~python noobie~
答案 0 :(得分:0)
我决定将xlsx文件转换为csv文件似乎更快