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!
Cet exercice fait partie du cours
Introduction to NoSQL
Instructions
- Update the connection URI to create a connection to the
disneyland
database, over port5432
. - Use
pandas
to read the results of the provided SQL query into a DataFrame, using the connection object created in the previous step.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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)