BaşlayınÜcretsiz Başlayın

Prepare data for the snake plot

Now you will prepare data for the snake plot. You will use the 3-cluster RFM segmentation solution you have built previously. You will transform the normalized RFM data into a long format by "melting" the metric columns into two columns - one for the name of the metric, and another for the actual numeric value.

We have loaded the normalized RFM data with the cluster labels already assigned. It is loaded as apandas DataFrame named datamart_normalized. Also, pandas is imported as pd.

Explore the datamart_normalized in the console before you begin the exercise to get a good sense of its structure!

Bu egzersiz

Customer Segmentation in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Transform the dataset into long format by applying melt function on the normalized dataset with a reset index.
  • Assign CustomerID and Cluster as ID variables.
  • Assign RFM values as value variables.
  • Name the variable as Metric and the value as Value.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Melt the normalized dataset and reset the index
datamart_melt = pd.____(
  					____.____(), 
                        
# Assign CustomerID and Cluster as ID variables
                    ____=['____', '____'],

# Assign RFM values as value variables
                    ____=['____', '____', '____'], 
                        
# Name the variable and value
                    ____='____', ____='____'
					)
Kodu Düzenle ve Çalıştır