Skip to main content

Posts

Showing posts from January, 2019

Connect Jupyter Notebook Pandas to Postgres

First install Python library Psycopg2 to connect to PostgreSQL: !pip install psycopg2 Now import the necessary libraries: import pandas as pd import psycopg2 as pg import pandas.io.sql as psql Connect to the DB Server: conn = pg.connect("postgres://username:password@server:port/dbname") Execute a Query: df = pd.read_sql('select* from table_name', conn) df.head()