Skip to content

Instantly share code, notes, and snippets.

@harshsinghal
Last active July 2, 2019 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshsinghal/38148dfc64a2ede93102fd9984c4da8f to your computer and use it in GitHub Desktop.
Save harshsinghal/38148dfc64a2ede93102fd9984c4da8f to your computer and use it in GitHub Desktop.
Grab data using pandas and insert into PostgreSQL db
# Used in blog post https://harshsinghal.dev/post/learn-sql-in-a-browser-with-postgresql-and-pgweb.html
import pandas as pd
from sqlalchemy import create_engine
iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
engine = create_engine('postgresql://postgres:postgres@localhost:5432/postgres')
iris.to_sql("iris", engine, if_exists = 'replace', index=False, chunksize=1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment