题解 | #某店铺用户消费特征评分#
某店铺用户消费特征评分
https://www.nowcoder.com/practice/200c824e9ed4428491c27d65ec56067d
import pandas as pd df=pd.read_csv('sales.csv',sep=',') df_des=df.describe() def score_r(number): if number<=df_des.loc['25%','recency']: return 4 elif number>df_des.loc['25%','recency'] and number<=df_des.loc['50%','recency']: return 3 elif number>df_des.loc['50%','recency'] and number<=df_des.loc['75%','recency']: return 2 else: return 1 def score_f(number): if number<=df_des.loc['25%','frequency']: return 1 elif number>df_des.loc['25%','frequency'] and number<=df_des.loc['50%','frequency']: return 2 elif number>df_des.loc['50%','frequency'] and number<=df_des.loc['75%','frequency']: return 3 else: return 4 def score_m(number): if number<=df_des.loc['25%','monetary']: return 1 elif number>df_des.loc['25%','monetary'] and number<=df_des.loc['50%','monetary']: return 2 elif number>df_des.loc['50%','monetary'] and number<=df_des.loc['75%','monetary']: return 3 else: return 4 df['R_Quartile']=df.recency.apply(score_r) df['F_Quartile']=df.recency.apply(score_f) df['M_Quartile']=df.recency.apply(score_m) print(df.head(5))