Get startedGet started for free

Querying the table

Now that you have a grasp of what's happening in the datacamp_application database, let's go ahead and write up a query for that database.

The goal is to get a feeling for the data in this exercise. You'll get the rating data for three sample users and then use a predefined helper function, print_user_comparison(), to compare the sets of course ids these users rated.

This exercise is part of the course

Introduction to Data Engineering

View Course

Exercise instructions

  • Complete the connection URI. The database is called datacamp_application. The host is localhost with port 5432. The username is repl and the password is password.
  • Select the ratings of users with id: 4387, 18163 and 8770.
  • Fill in print_user_comparison() with the three users you selected.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Complete the connection URI
connection_uri = "postgresql://____:____@____:____/datacamp_application" 
db_engine = sqlalchemy.create_engine(connection_uri)

# Get user with id 4387
user1 = pd.read_sql("SELECT * FROM rating ____ ____=____", db_engine)

# Get user with id 18163
user2 = pd.read_sql("SELECT * FROM rating ____ ____=____", db_engine)

# Get user with id 8770
user3 = pd.read_sql("SELECT * FROM rating ____ ____=____", db_engine)

# Use the helper function to compare the 3 users
print_user_comparison(____, ____, ____)
Edit and Run Code