import csv import sys results = [] print("DROP TABLE IF EXISTS rate;") print("CREATE TABLE IF NOT EXISTS rate (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, date DATE, currency TEXT, rate FLOAT);"); with open(sys.argv[1]) as f: reader = csv.DictReader(f) for currencies in reader: date = currencies['Date'] del currencies['Date'] for currency in currencies.keys(): # skip the blank ones if currency != '': rate = currencies[currency] rate = rate == "N/A" and "null" or rate print(f"INSERT INTO rate (date, currency, rate) VALUES ('{date}', '{currency}', { rate });")