Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # this will convert pandas dtaframe to list of list
- crypto_list = crypto_df.values.tolist()
- # lets make new connection to Insert crypto data in SQL DB
- conn = sqlite3.connect('session.db')
- # make a cursor - it will help with querying SQL DB
- cur = conn.cursor()
- try:
- # will use ? sign to represent each column names inside VALUE().
- cur.executemany("INSERT INTO Crypto(ASSET, NAME, Date, Open, High, Low, Close) VALUES (?,?,?,?,?,?,?)", crypto_list)
- conn.commit()
- print('Data Inserted Successfully')
- except Exception as e:
- print(str(e))
- print('Data Insertion Failed')
- finally:
- # finally block will help with always closing the connection to DB even in case of error.
- conn.close()
- # Output: Data Inserted Successfully
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement