Reputation: 85
I'm looking for a way to create a postgres table from a pandas dataframe, and then read the postgre table directly in pgAdmin. I've found a way to do that thanks to this link : How to write DataFrame to postgres table? .
The command is :
from sqlalchemy import create_engine
engine = create_engine('postgresql://username:password@host:port/database')
df.to_sql('table_name', engine)
However, I don't know what is 'table_name'. Do I have to create a table in my Data Base?
Thanks for your help!
Upvotes: 1
Views: 11770
Reputation: 4653
A table with the name you specify will be created if it does not already exist. https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html
Upvotes: 3