How Do I Import a Csv File from Sqlite to Python

con = sqlite3. connect(“data.db”)cur = con. cursor()a_file = open(“test.csv”)rows = csv. reader(a_file)cur. executemany(“INSERT INTO data VALUES (?, ?)”, rows)cur. execute(“SELECT * FROM data”)print(cur. fetchall())con. commit()

How do I import a CSV file into SQLite python?

  1. con = sqlite3. connect(“data.db”)
  2. cur = con. cursor()
  3. a_file = open(“test.csv”)
  4. rows = csv. reader(a_file)
  5. cur. executemany(“INSERT INTO data VALUES (?, ?)”, rows)
  6. cur. execute(“SELECT * FROM data”)
  7. print(cur. fetchall())
  8. con. commit()

How do I read a csv file in SQLite?

  1. Open the destination table to view then choose File -> Import CSV from the menu.
  2. Or you can right-click on the table name from the right panel (or even any data cell of the table), choose Import CSV .
David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest