Skip to content

Instantly share code, notes, and snippets.

@mujahidk
Created February 3, 2020 21:42
Show Gist options
  • Save mujahidk/f0dfe53a558572d48c682761f69a842b to your computer and use it in GitHub Desktop.
Save mujahidk/f0dfe53a558572d48c682761f69a842b to your computer and use it in GitHub Desktop.
Python connection to PostgreSQL and Pandas
# Shell
# pip --version
# pip install psycopg2-binary
import psycopg2 as pg
import pandas as pd
connection = pg.connect("host='host-name-here' dbname=DBNAME user='username' password='password'")
df = pd.read_sql_query("SELECT * FROM product", connection)
df.sample(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment