Customer Segmentation in Python
Karolis Urbonas
Head of Data Science, Amazon
datamart.groupby('RFM_Segment').size().sort_values(ascending=False)[:10]
datamart[datamart['RFM_Segment']=='111'][:5]
datamart.groupby('RFM_Score').agg({
'Recency': 'mean',
'Frequency': 'mean',
'MonetaryValue': ['mean', 'count'] })/
.round(1)
Use RFM score to group customers into Gold, Silver and Bronze segments.
def segment_me(df): if df['RFM_Score'] >= 9: return 'Gold' elif (df['RFM_Score'] >= 5) and (df['RFM_Score'] < 9): return 'Silver' else: return 'Bronze'
datamart['General_Segment'] = datamart.apply(segment_me, axis=1)
datamart.groupby('General_Segment').agg({ 'Recency': 'mean', 'Frequency': 'mean', 'MonetaryValue': ['mean', 'count']}).round(1)
Customer Segmentation in Python