0

I have a pandas DataFrame,df, that I want to append to a remote table TabB on a postgres db. Both tables shares the same columns. How can I perform this using pandas and sql alchemy?

My sqlalchemy engine is defined as this:

myengine=create_engine('postgresql://postgres:[email protected]:5433/mydb') 

I would like to know if I can apply a method like df.read_sql() to pass a proper INSERT TO. Any example would be greatly appreciated. Thanks in advance!

0

1 Answer 1

1

In pandas=0.20.3 I generally use something like that:

db_engine=create_engine('postgresql://postgres:[email protected]:5433/mydb')
df_to_save.to_sql(con=db_engine, name='yourTable', if_exists='append', index=False)

df_to_save and yourTable needs to have the same columns

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.