The target table
In the previous exercises, you've calculated a DataFrame called recommendations
. It contains pairs of user_id
's' and course_id
's, with a rating that represents the average rating of this course. The assumption is the highest rated course, which is eligible for a user would be best to recommend.
It's time to put this table into a database so that it can be used by several products like a recommendation engine or an emailing system.
Since it's a pandas.DataFrame
object, you can use the .to_sql()
method. Of course, you'll have to connect to the database using the connection URI first. The recommendations
table is available in your environment.
This exercise is part of the course
Introduction to Data Engineering
Exercise instructions
- Fill in the connection URI for the Postgres database on host
localhost
with port5432
. You can connect with userrepl
and passwordpassword
. The database name isdwh
. - Complete the
load_to_dwh()
function. It should write to the"recommendations"
table and replace the table if it already exists.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
connection_uri = "____://____:____@____:____/____"
db_engine = sqlalchemy.create_engine(connection_uri)
def load_to_dwh(recommendations):
recommendations.____("____", ____, ____="____")