Calculate 3 groups for recency and frequency
You will now group the customers into three separate groups based on Recency
, and Frequency
.
The dataset has been loaded as datamart
, you can use console to view top rows of it. Also, pandas
has been loaded as pd
.
We will use the result from the exercise in the next one, where you will group customers based on the MonetaryValue
and finally calculate and RFM_Score
.
Once completed, print the results to the screen to make sure you have successfully created the quartile columns.
This exercise is part of the course
Customer Segmentation in Python
Exercise instructions
- Create labels for
Recency
with a decreasing range of 3 through 1, and labels forFrequency
with an increasing range of 1 through 3. - Assign these labels to three equal percentile groups based on
Recency
. - Assign these labels to three equal percentile groups based on
Frequency
. - Create new quantile columns
R
andF
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create labels for Recency and Frequency
r_labels = range(____, 0, ____); f_labels = range(1, ____)
# Assign these labels to three equal percentile groups
r_groups = pd.qcut(datamart['____'], q=____, labels=____)
# Assign these labels to three equal percentile groups
f_groups = pd.qcut(datamart['____'], q=____, labels=____)
# Create new columns R and F
datamart = datamart.assign(____=____.values, ____=____.values)