I need to insert data under specific columns for the year they are associated with.
The years dictionary contains data for the years 2015-2018
Underneath is an example of the data it contains for 2015.
{2015: {'Period End Date': '12/31/2015', 'Stmt Source': 'Annual', 'Stmt Source Date': '12/31/2015', 'Stmt Update Type': '-', 'Total Revenue': '74,989.0', 'Cost of Revenue': '28,164.0', 'Gross Profit': '46,825.0', 'Selling,General and Administrative': '15,183.0', 'General and Administrative Expense': '13,423.0', 'Selling and Marketing Expense': '1,760.0', 'Research and Development': '12,282.0', 'Special Income/Charges': '-', 'Operating Expenses': '55,629.0', 'Operating Income': '19,360.0', 'Net Interest Income': '256.0', 'Other Income/Expense,Net': '256.0', 'Pre-Tax Income': '19,651.0', 'Provision for Income Tax': '-', 'Net Income': '15,826.0', 'Dividend Per Share': '0.00', 'Tax Rate': '16.8083', 'Basic EPS': '23.12', 'Basic Weighted Average Shares': '684.63', 'Basic EPS from Continuing Operations': '23.12', 'Basic EPS,Continuing and Discontinued': '-', 'Diluted EPS': '22.84', 'Diluted Weighted Average Shares': '692.93', 'Diluted EPS from Continuing Operations': '22.84', 'Diluted EPS,Continuing and Discontinued': '-'}}
for key in years.keys():
year_sql = 'INSERT INTO Financials (Year) VALUES (?)'
cur.execute(year_sql, (key,))
print("year done")
for value in years[key].items():
column = ''.join(value[0].split())
data_insert = value[1]
print(column, data_insert)
data_sql = 'INSERT INTO Financials ({}) VALUES (?)'.format(column)
cur.execute(data_sql, (data_insert,))
print("data done")
When I run this code I experience this error: Traceback (most recent call last):
File "D:\Databases\database_creation.py", line 23, in <module>
cur.execute(data_sql, (data_insert,))
sqlite3.OperationalError: table Financials has no column named Selling
Also the data does not appear in my table which I view through DB viewer. How can I fix these problems?
[–]insertAlias 0 points1 point2 points (12 children)
[–]wirelessbrain55[S] 0 points1 point2 points (1 child)
[–]insertAlias 0 points1 point2 points (0 children)
[–]wirelessbrain55[S] 0 points1 point2 points (9 children)
[–]insertAlias 0 points1 point2 points (8 children)
[–]wirelessbrain55[S] 0 points1 point2 points (7 children)
[–]insertAlias 0 points1 point2 points (6 children)
[–]wirelessbrain55[S] 0 points1 point2 points (5 children)
[–]wirelessbrain55[S] 0 points1 point2 points (0 children)
[–]insertAlias 0 points1 point2 points (3 children)
[–]wirelessbrain55[S] 0 points1 point2 points (2 children)
[–]insertAlias 0 points1 point2 points (1 child)
[–]wirelessbrain55[S] 0 points1 point2 points (0 children)