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!
Diese Übung ist Teil des Kurses
Introduction to NoSQL
Anleitung zur Übung
- 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.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
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)