Since pandas 0.14, the sql functions also support postgresql (via SQLAlchemy, so all database flavors supported by SQLAlchemy work). So you can simply use to_sql
to write a pandas DataFrame to a PostgreSQL database:
import pandas as pd
from sqlalchemy import create_engine
import psycopg2
engine = create_engine('postgresql://scott:tiger@localhost:5432/mydatabase')
df.to_sql("table_name", engine)
See the docs: http://pandas.pydata.org/pandas-docs/stable/io.html#sql-queries
If you have an older version of pandas (< 0.14), see this question:How to write DataFrame to postgres table?