Return Pandas dataframe from PostgreSQL query with sqlalchemy

后端 未结 3 1869
走了就别回头了
走了就别回头了 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:55

    Read postgres sql data in pandas in given below and image link

    import psycopg2 as pg
    import pandas.io.sql as psql
    connection = pg.connect("host=localhost dbname=kinder user=your_username password=your_password")
    dataframe = psql.read_sql('SELECT * FROM product_product', connection)
    product_category = psql.read_sql_query('select * from product_category', connection)
    

    https://i.stack.imgur.com/1bege.png

提交回复
热议问题