今日重点
1 零售会员分析
透视表/分组聚合
数据可视化
2 RFM 会员价值度分析
分组聚合分析
数据可视化
业务问题
1 零售会员分析
1.1 会员存量增量分析
custom_info.pivot_table(index='注册年月',values='会员卡号',aggfunc='count')
month_count = custom_info.groupby('注册年月')[['会员卡号']].count()
month_count.columns = ['月会员增量']
month_count['会员存量'] = month_count['月会员增量'].cumsum()
数据可视化
import matplotlib.pyplot as plt
month_count['月会员增量'].iloc[1:].plot(figsize = (16,8),color = 'red',secondary_y=True,ylabel = '月会员增量')
month_count['会员存量'].iloc[1:].plot.bar(color = 'gray',fontsize = 16)
plt.title('会员增量存量分析',fontsize=20)
plt.show()
同一个dataframe连着两次plot 图会画在同一个框中
secondary_y=True 指定副坐标轴
fontsize 调整字体大小
legend 添加图例
1.2 会员增量等级分布
透视表和分组聚合实际上功能相同
custom_info.groupby(['注册年月','会员等级'])['会员卡号'