7

Is it possible to write a Pandas dataframe to PostgreSQL database using psycopg2?

Endgoal is to be able to write a Pandas dataframe to Amazon RDS PostgreSQL instance.

1 Answer 1

2

If you use a SQLAlchemy engine around psycopg2, you could probably use df.to_sql. See: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I got SQLAlchemy to work. After using df.to_sql to write is commit necessary? If so, how would I commit in SQLAlchemy? It appears I need to create a session object then somehow add my query to it and then commit.
I believe to_sql performs the commit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.