(TIL) Pandas: Write DataFrame to table with to_sql

less than 1 minute read

You can write DataFrames to a database table via a sqlalchemy connection as follows:

from sqlalchemy import create_engine
engine = create_engine('postgresql://scott:tiger@localhost:5432/mydatabase')
df.to_sql('table_name', engine)

Via StackOverflow.

Comments