Splitting the rental rate
In the video exercise, you saw how to use pandas to split the email address column of the film
table in order to extract the users' domain names. Suppose you would want to have a better understanding of the rates users pay for movies, so you decided to divide the rental_rate
column into dollars and cents.
In this exercise, you will use the same techniques used in the video exercises to do just that! The film
table has been loaded into the pandas
DataFrame film_df
. Remember, the goal is to split up the rental_rate
column into dollars and cents.
This exercise is part of the course
Introduction to Data Engineering
Exercise instructions
- Use the
.astype()
method to convert therental_rate
column into a column of string objects, and assign the results torental_rate_str
. - Split
rental_rate_str
on'.'
and expand the results into columns. Assign the results torental_rate_expanded
. - Assign the newly created columns into
films_df
using the column namesrental_rate_dollar
andrental_rate_cents
respectively, setting them to the expanded version using the appropriate index.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Get the rental rate column as a string
rental_rate_str = film_df.____.____("____")
# Split up and expand the column
rental_rate_expanded = rental_rate_str.____.____("____", expand=True)
# Assign the columns to film_df
film_df = film_df.assign(
____=____[____],
____=____[____],
)