Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Customer Segmentation in Python

Cursus bekijken

Oefeninstructies

  • 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 in data.
  • Print data with sorted Recency_Days values.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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'))
Code bewerken en uitvoeren