Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. # this will convert pandas dtaframe to list of list
  2. crypto_list = crypto_df.values.tolist()
  3.  
  4. # lets make new connection to Insert crypto data in SQL DB
  5. conn = sqlite3.connect('session.db')
  6.  
  7. # make a cursor - it will help with querying SQL DB
  8. cur = conn.cursor()
  9.  
  10. try:
  11. # will use ? sign to represent each column names inside VALUE().
  12. cur.executemany("INSERT INTO Crypto(ASSET, NAME, Date, Open, High, Low, Close) VALUES (?,?,?,?,?,?,?)", crypto_list)
  13. conn.commit()
  14. print('Data Inserted Successfully')
  15. except Exception as e:
  16. print(str(e))
  17. print('Data Insertion Failed')
  18. finally:
  19. # finally block will help with always closing the connection to DB even in case of error.
  20. conn.close()
  21.  
  22. # Output: Data Inserted Successfully
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement