Skip to content

Instantly share code, notes, and snippets.

@SaraM92
Last active September 13, 2020 22:30
Show Gist options
  • Save SaraM92/5b445d5b56be2d349cdfa988204ff5f3 to your computer and use it in GitHub Desktop.
Save SaraM92/5b445d5b56be2d349cdfa988204ff5f3 to your computer and use it in GitHub Desktop.
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