Created
June 5, 2018 12:16
-
-
Save nticaric/163034020c73c893d9aee4cd95f62df5 to your computer and use it in GitHub Desktop.
Converting CSV to sqlite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This example requires CSVkit (https://github.com/wireservice/csvkit). A Python toolset with a lot of very cool CSV tools. | |
# IMPORTANT NOTE: make sure to use a proper csv file. I had a lot of trouble with a csv file created by a service with Dutch | |
# as locale. Changing it to US solved the problem. Some locales use comma's to seperate point numbers. A semicolon is then | |
# used. | |
# Create table example and Load file-a.csv into it | |
csvsql --db sqlite:///example.db --table example --insert file-a.csv | |
# Add an extra file to table example | |
csvsql --db sqlite:///example.db --table example --no-create --insert file-b.csv | |
# Query the database with direct CSV output. | |
sql2csv --db sqlite:///example.db --query 'select avg(age) from example' | |
# Connect directly to the database | |
sqlite3 example.db | |
$ .tables # show the available tables | |
$ .schema example # show the structure of table example | |
$ select column-b, count(*) as total from example group by column-b having count(*) > 2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment