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

后端 未结 2 1900
长发绾君心
长发绾君心 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 03:57

    I have encountered this error recently and it was solved my removing the .pyc files located in the same directory as .py files. These files (.pyc) holds the previous version information and time, date.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题