Forked from jakebrinkmann/connect_psycopg2_to_pandas.py
Created
May 25, 2021 11:00
-
-
Save SwapnilShirke/2b9b27e0a27db5bd9b47023a5bd8a3e8 to your computer and use it in GitHub Desktop.
Read SQL query from psycopg2 into pandas dataframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment