1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Data Engineering

Connected

Exercise

Read from a database

In this exercise, you're going to extract data that resides inside tables of a local PostgreSQL database. The data you'll be using is the Pagila example database. The database backs a fictional DVD store application, and educational resources often use it as an example database.

You'll be creating and using a function that extracts a database table into a pandas DataFrame object. The tables you'll be extracting are:

  • film: the films that are rented out in the DVD store.
  • customer: the customers that rented films at the DVD store.

In order to connect to the database, you'll have to use a PostgreSQL connection URI, which looks something like this:

postgresql://[user[:password]@][host][:port][/database]

Instructions

100 XP
  • Complete the extract_table_to_pandas() function definition to include the tablename argument within the query.
  • Fill in the connection URI. The username and password are repl and password, respectively. The host is localhost and port is 5432. The database is pagila.
  • Complete the function calls of extract_table_to_pandas() to extract the film and customer tables.