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

Calculate spend quartiles (q=4)

We have created a dataset for you with random CustomerID and Spend values as data. You will now use this dataset to group customers into quartiles based on Spend values and assign labels to each of them.

pandas library as been loaded as pd. Feel free to print the data to the console.

Bu egzersiz

Customer Segmentation in Python

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

Egzersiz talimatları

  • Create a spend quartile with 4 groups - a range between 1 and 5.
  • Assign the quartile values to the Spend_Quartile column in data.
  • Sort data based on the Spend values and print the result.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Create a spend quartile with 4 groups - a range between 1 and 5
spend_quartile = pd.____(data['Spend'], q=____, labels=range(1,____))

# Assign the quartile values to the Spend_Quartile column in data
data['____'] = spend_quartile

# Print data with sorted Spend values
print(____.sort_values(____))
Kodu Düzenle ve Çalıştır