Return Pandas dataframe from PostgreSQL query with sqlalchemy

后端 未结 3 1874
走了就别回头了
走了就别回头了 2021-01-30 10:08

I want to query a PostgreSQL database and return the output as a Pandas dataframe.

I created a connection to the database with \'SqlAlchemy\':

from sqlal         


        
3条回答
  •  庸人自扰
    2021-01-30 10:40

    The error message is telling you that a table named:

    stat_table
    

    does not exist( a relation is a table in postgres speak). So, of course you can't select rows from it. Check your db after executing:

    i.to_sql('Stat_Table',engine,if_exists='replace')
    

    and see if a table by that name got created in your db.

    When I use your read statement:

    df = pd.read_sql_query('select * from Stat_Table',con=engine)
    

    I get the data back from a postgres db, so there's nothing wrong with it.

提交回复
热议问题