arundhaj

all that is technology

Pandas with Postgres datasource

 

We would be getting data from different sources for doing data analysis. Most common being from files, we might even source from databases.

This post will show how to load data from postgres database to pandas DataFrame. pandas is a python based data analysis tool.

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 id, price FROM stock_price", connection)

Make sure the packages are installed.

This simple snippet would come handy at times.

Comments