Skip to content

Instantly share code, notes, and snippets.

@Anubhav722
Forked from 00krishna/pandas.postgres.py
Created November 7, 2017 08:18
Show Gist options
  • Select an option

  • Save Anubhav722/201f7ee0dfc27004b4d20a7edea4a6f7 to your computer and use it in GitHub Desktop.

Select an option

Save Anubhav722/201f7ee0dfc27004b4d20a7edea4a6f7 to your computer and use it in GitHub Desktop.
Connect from python pandas to a postgresql database and pull data.
import psycopg2 as pg
import pandas.io.sql as psql
# get connected to the database
connection = pg.connect("dbname=mydatabase user=postgres")
dataframe = psql.frame_query("SELECT * FROM <tablename>", connection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment