根据RFM类别,我对客户进行了细分,因为我的某些客户属于多个类别,因此我必须将客户细分为所属的类别,并添加到我的rfm表中(添加单独的“ segment”列)< / p>
CardNo最近频率货币R_Quartile F_Quartile M_Quartile RFMClass段
我的rfmtable列类似于上面的内容,但我想将其添加到rfm表中的“段”列除外
我到目前为止所做的是
for card_no in rfmSegmentation['CardNo']:
> for num in rfmSegmentation['RFMClass']:
> num = str(num)
> if int(num[0])==1 and int(num[1])==1 and int(num[2])==1:
> print("RFM_class",num,"cardno",card_no,"Best Customer")
> elif int(num[1])==1:
> print("RFM_class",num,"cardno",card_no,"Loyal Customer")
> elif int(num[2])==1:
> print("RFM_class",num,"cardno",card_no,"Big Spender")
> elif int(num[0])==3 and int(num[1])==1 and int(num[2])==1:
> print("RFM_class",num,"cardno",card_no,"Almost Lost")
> elif int(num[0])==4 and int(num[1])==1 and int(num[2])==1:
> print("RFM_class",num,"cardno",card_no,"Lost Customer")
> elif int(num[0])==4 and int(num[1])==4 and int(num[2])==4:
> print("RFM_class",num,"cardno",card_no,"Lost Cheap Customer")
它打印每个客户的细分,但我想将此添加为rfmtable中的单独列并将其转换为CSV文件
任何帮助将不胜感激
答案 0 :(得分:0)
> I think I found a solution
>
> segment = []
>
> for row in rfmSegmentation['RFMClass']:
> row = str(row)
> if int(row[0])==1 and int(row[1])==1 and int(row[2])==1:
> segment.append('Best Customer')
> elif int(row[1])==1:
> segment.append('Loyal Customer')
> elif int(row[2])==1:
> segment.append('Big Spender')
> elif int(row[0])==3 and int(row[1])==1 and int(row[2])==1:
> segment.append('Almost Lost')
> elif int(row[0])==4 and int(row[1])==1 and int(row[2])==1:
> segment.append('Lost Customer')
> elif int(row[0])==4 and int(row[1])==4 and int(row[2])==4:
> segment.append('Lost Cheap Customer')
> else:
> segment.append('Failed')
>
> rfmSegmentation['segment'] = segment