Calculate recency deciles (q=4)
We have created a dataset for you with random CustomerID
and Recency_Days
values as data
. You will now use this dataset to group customers into quartiles based on Recency_Days
values and assign labels to each of them.
Be cautious about the labels for this exercise. You will see that the labels are inverse, and will required one additional step in separately creating them. If you need to refresh your memory on the process of creating the labels, check out the slides!
The pandas
library as been loaded as pd
. Feel free to print the data
to the console.
This exercise is part of the course
Customer Segmentation in Python
Exercise instructions
- Store labels from 4 to 1 in a decreasing order.
- Create a spend quartile with 4 groups and pass the previously created labels.
- Assign the quartile values to the
Recency_Quartile
column indata
. - Print
data
with sortedRecency_Days
values.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Store labels from 4 to 1 in a decreasing order
r_labels = list(range(____, 0, ____))
# Create a spend quartile with 4 groups and pass the previously created labels
recency_quartiles = pd.____(data['Recency_Days'], q=____, labels=r_labels)
# Assign the quartile values to the Recency_Quartile column in `data`
data['____'] = recency_quartiles
# Print `data` with sorted Recency_Days values
print(data.____('Recency_Days'))