Last active
September 13, 2020 22:30
-
-
Save SaraM92/5b445d5b56be2d349cdfa988204ff5f3 to your computer and use it in GitHub Desktop.
This file contains 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
import sqlite3 | |
csv = "https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv" | |
# Create a new database file: | |
db = sqlite3.connect("cases.sqlite") | |
# Load the CSV in chunks: | |
for c in pd.read_csv(csv, chunksize=100): | |
# Append all rows to a new database table | |
c.to_sql("cases", db, if_exists="append") | |
# Add an index on the 'state' column: | |
db.execute("CREATE INDEX state ON cases(state)") | |
db.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment