Skip to content

Instantly share code, notes, and snippets.

@guillaume-martin
Created July 28, 2017 07:09
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 guillaume-martin/16da086c70c1369d86bd4008b12c2328 to your computer and use it in GitHub Desktop.
Save guillaume-martin/16da086c70c1369d86bd4008b12c2328 to your computer and use it in GitHub Desktop.
Create a pandas dataframe from an sql query to a remote psql database
import pandas as pd
from sqlalchemy import create_engine
driver = "postgresql"
server = ""
port = "5432"
database = ""
uid = ""
pwd = ""
engine = create_engine("{}://{}:{}@{}:{}/{}".format(driver, uid, pwd, server, port, database))
sql = "SELECT * FROM table"
df = pd.read_sql_query(sql, con=engine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment