Mulai sekarangMulai gratis

Creating custom segments

It's your turn to create a custom segmentation based on RFM_Score values. You will create a function to build segmentation and then assign it to each customer.

The dataset with the RFM values, RFM Segment and Score has been loaded as datamart, together with pandas and numpy libraries. Feel free to explore the data in the console.

Latihan ini merupakan bagian dari kursus

Customer Segmentation in Python

Lihat Kursus

Instruksi latihan

  • Create segments named Top, Middle, Low. If the RFM score is greater than or equal to 10, the level should be "Top". If it's between 6 and 10 it should be "Middle", and otherwise it should be "Low".
  • Apply the rfm_level function and store it as RFM_Level value.
  • Print the header with top 5 rows of the datamart.

Latihan interaktif langsung praktik

Cobalah latihan ini dengan melengkapi kode contoh ini.

# Define rfm_level function
def rfm_level(df):
    if df['RFM_Score'] >= ____:
        return '____'
    elif ((df['RFM_Score'] >= ____) and (df['RFM_Score'] < ____)):
        return '____'
    else:
        return '____'

# Create a new variable RFM_Level
datamart['____'] = datamart.apply(____, axis=1)

# Print the header with top 5 rows to the console
print(datamart.____())
Edit dan Jalankan Kode