The Hello World of SQL Queries!
Now, it's time for liftoff! In this exercise, you'll perform the Hello World of SQL queries, SELECT, in order to retrieve all columns of the table Album in the Chinook database. Recall that the query SELECT * selects all columns.
This exercise is part of the course
Introduction to Importing Data in Python
Exercise instructions
- Open the engine connection as
conusing the method.connect()on the engine. - Execute the query that selects ALL columns from the
Albumtable. Store the results inrs. - Store all of your query results in the DataFrame
dfby applying the.fetchall()method to the resultsrs. - Close the connection!
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import packages
from sqlalchemy import create_engine
import pandas as pd
# Create engine: engine
engine = create_engine('sqlite:///Chinook.sqlite')
# Open engine connection: con
# Perform query: rs
rs = con.execute(____)
# Save results of the query to DataFrame: df
df = pd.DataFrame(____)
# Close connection
# Print head of DataFrame df
print(df.head())