Postgresql
PostgreSQL query to Pandas DataFrame
Run a sql query and crate pandas data frame. Select query is recommended for creating dataframe. Credentials are loaded from .env file. Any errors in query will raise an exception.
mlmachine-learningsqlpostgrespsycopg
Required packages
You need below packages to use the code generated by recipe. All packages are automatically installed in MLJAR Studio.
psycopg>=3.2.1
pandas>=1.0.0
Interactive recipe
You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.
In the below recipe, we assume that you have following variables available in your notebook:
- conn (type Connection)
Python code
# Python code will be here
Code explanation
- Check if there is an open connection.
- If not then open the connection.
- Try to run query.
- If run a select query, try to create data frame.
- Show df shape and head.
- If error occurs raise exception.
Example Python notebooks
Please find inspiration in example notebooks
Postgresql cookbook
Code recipes from Postgresql cookbook.
- « Previous
- Show all columns
- Next »
- Raw query