I am new to using postgreSQL in Python and using Pandas.
I am trying to create a pandas dataframe from a query, with the following:
with conn.cursor() as cur:
cur.execute('SELECT * FROM payment')
postgres_df = pd.read_sql_query('SELECT * FROM payment', conn)
print(postgres_df)
conn.close()
But when I run the code I do get a result, but also a UserWarning.
UserWarning: pandas only support SQLAlchemy connectable(engine/connection) ordatabase string URI or sqlite3 DBAPI2 connectionother DBAPI2 objects are not tested, please consider using SQLAlchemy
warnings.warn(
I am using the psycopg2
package to connect to PostgreSQL.
I would like to know if the code to creating a dataframe can be more efficiently written.
Then, should I be using SQLAlchemy
instead of psycopg2
or is there a way to continue using the same package without getting a warning.