I made a post earlier (Getting excel data into Database - beginner) about getting data into SQlite.
I have done some further research and now understand the basics, therefore I have created the following code:
import sqlite3
conn = sqlite3.connect('financials.db')
cur = conn.cursor()
cur.execute('DROP TABLE IF EXISTS financials')
cur.execute('''
CREATE TABLE "financials"(
"Mkt_Cap" REAL,
"EV" REAL,
"PE" REAL,
"Yield" REAL
)
''')
fname = input('Enter the name of the csv file:')
if len(fname) < 1 : fname="data.csv"
with open(fname) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
print(row)
Below is how my CSV data is currently formatted (It just gets scraped and put into a CSV file):
Given that, would I be able to extract the values of the table rows using something like this:
Mkt_cap=row[0]
EV = row[1]
I would then write an Insert command and commit to get the data into the database.
Or do I need to reformat my CSV data?