Executing queries with sqlalchemy and pandas
To work with data stored in Postgres tables, you'll use sqlalchemy's create_engine(), and pandas's read_sql() functions. To get the hang of these tools, you'll practice connecting to a Postgres database, and executing a query. Good luck!
This exercise is part of the course
Introduction to NoSQL
Exercise instructions
- Update the connection URI to create a connection to the
disneylanddatabase, over port5432. - Use
pandasto read the results of the provided SQL query into a DataFrame, using the connection object created in the previous step.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
import pandas as pd
import sqlalchemy
# Create a connection to the reviews database
db_engine = sqlalchemy.____("postgresql+psycopg2://repl:password@localhost:____/____")
# Execute a query against the nested_reviews table
results = pd.____("SELECT * FROM nested_reviews;", ____)
print(results)