LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Customer Segmentation in Python

Kurs anzeigen

Anleitung zur Übung

  • Create labels for Recency with a decreasing range of 3 through 1, and labels for Frequency 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 and F.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# 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)
Code bearbeiten und ausführen