Skip to content

Instantly share code, notes, and snippets.

View SwapnilShirke's full-sized avatar
🏠
Working from home

Swapnil Dattatray Shirke SwapnilShirke

🏠
Working from home
View GitHub Profile
@SwapnilShirke
SwapnilShirke / connect_psycopg2_to_pandas.py
Created May 25, 2021 11:00 — forked from jakebrinkmann/connect_psycopg2_to_pandas.py
Read SQL query from psycopg2 into pandas dataframe
import pandas as pd
import pandas.io.sql as sqlio
import psycopg2
conn = psycopg2.connect("host='{}' port={} dbname='{}' user={} password={}".format(host, port, dbname, username, pwd))
sql = "select count(*) from table;"
dat = sqlio.read_sql_query(sql, conn)
conn = None