I have a simple GeoPandas Dataframe:
I would like to upload this GeoDataframe to a PostGIS table. I have a Database setup with the PostGIS extension already but can't seem to add this Dataframe as a table.
I have tried the following:
engine = <>
meta = MetaData(engine)
eld_test = Table('eld_test', meta, Column('id', Integer, primary_key=True), Column('key_comb_drvr', Text),
Column('geometry', Geometry('Point', srid=4326)))
eld_test.create(engine)
conn = engine.connect()
conn.execute(eld_test.insert(), df.to_dict('records'))
Best Answer
Using Panda's to_sql method and SQLAlchemy you can store a dataframe in Postgres. And since you're storing a Geodataframe, GeoAlchemy will handle the geom column for you. Here's a code sample:
Worth noting that 'if_exists' parameter allows you to handle the way the dataframe will be added to your postgres table: