ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Customer Segmentation in Python

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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'))
Editar y ejecutar código