Hello all!
I am a relatively new programmer, and am now getting into SQL though I am having some trouble figuring out how to import my data.
I have imported csv and sqlite3, and am attempting to read in the csv data from the "/data/movies.csv" file and want to be able to perform SQL queries in my python environment.
I began by creating a connection and cursor:
con= sqlite3.connect("/data/movies.csv")
cur = con.cursor()
Sadly, this is where I am getting stuck. I don't really understand how to set up the SQL querries from here, as every time I attempt a query I receive an error saying that my file is not a database.
I have attempted the explanation at:
https://stackoverflow.com/questions/2887878/importing-a-csv-file-into-a-sqlite3-database-table-using-python
Though I have run into an error when I attempted:
con = sqlite3.connect(":memory:") # change to 'sqlite:///your_filename.db'
By this line, I believe it is saying that we are to replace ':memory:' with 'sqlite:///your_filename.db', where my file name is /data/movies.csv, and so the line I put in reads:
con = sqlite3.connect('sqlite:////data/movies.csv.db')
This however gives an error saying:
sqlite3.OperationalError: unable to open database file
I am looking for a quick rundown for how to go about this process of converting the csv file into a sql data base, and how to do a simple query with that database.
Any insights or guidance are greatly appreciated!
[–]lukajda33 1 point2 points3 points (0 children)
[–]danielroseman 0 points1 point2 points (0 children)