SQLAlchemy AttributeError: 'module' object has no attribute 'PandasSQLAlchemy'

后端 未结 2 1899
长发绾君心
长发绾君心 2021-01-25 03:06

I\'m writing a pandas Dataframe to a Postgres database:

from sqlalchemy import create_engine, MetaData
engine = create_engine(r\'postgresql://user:password@local         


        
2条回答
  •  走了就别回头了
    2021-01-25 04:00

    I suppose you are using pandas 0.15. PandasSQLAlchemy was not yet really public, and was renamed in pandas 0.15 to SQLDatabase. So if you replace that in your code, it should work (so pdsql = pd.io.sql.SQLDatabase(engine, meta=meta)).

    However, starting from pandas 0.15, there is also schema support in the read_sql_table and to_sql functions, so it should not be needed to make a MetaData and SQLDatabase object manually. Instead, this should do it:

    dataframe.to_sql(table_name, engine, schema='data_quality')
    

    See the 0.15 release notes: http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#improvements-in-the-sql-io-module

提交回复
热议问题