'How to save dataframe to postgres with column type of geometry?

I have dataframe with 4 columns: 'name', 'exp', 'geom', 'geom_utm'

The columns: geom, geom_utm contains WKB values.

df.dypes = all columns have the Object type

I want to save the df to postgres and set geom, geom_utm as geometry type.

df.to_sql(name='my_table', index=False, dtype={'name':sqlalchemy.types.Text,
'exp':sqlalchemy.types.Text,
'geom':sqlalchemy.types.Text,
'geom_utm':sqlalchemy.types.Text}, con=engine, schema='my_schm')

I didn't find sqlalchemy.types with geometry type.

How can I save those 2 columns with geometry type ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source