某CD网站数据用户行为分析

某CD网站数据用户行为分析

目录

一、数据预处理

1.1 数据导入

1.2 数据清洗

二、用户消费趋势分析

2.1每月消费总金额

2.2每月订单总数

2.3每月消费总产品数

2.4每月消费人数

2.5每月用户平均消费金额

2.6每月用户平均消费次数

三、用户个体消费分析

3.1 用户消费金额和次数的散点图

3.2 用户消费金额的分布图

3.3 用户消费次数的分布图

3.4用户累计消费金额占比

四、用户消费行为分析

4.1用户第一次消费(收购)

4.2用户最近一次消费

4.3新老客消费比

4.4用户分层

4.5用户生命周期分析

五、复购率和回购率分析

5.1复购率

5.2回购率

一、数据预处理

import pandas as pd
import numpy as np
columns = ['user_id','order_dt','order_products','order_amount']
df = pd.read_table('D:\\BaiduNetdiskDownload\\Pandas\\pandas_exercises-master\\CDNOW_master.txt',names=columns,sep='\s+')

由于原始数据中没有包含表头,导入数据时需要添加表头
use_id:用户id
order_dt:订单日期
order_products:购买产品数
order_amount:购买金额

df.head()
user_idorder_dtorder_productsorder_amount
0119970101111.77
1219970112112.00
2219970112577.00
3319970102220.76
4319970330220.76
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 69659 entries, 0 to 69658
Data columns (total 4 columns):
user_id           69659 non-null int64
order_dt          69659 non-null int64
order_products    69659 non-null int64
order_amount      69659 non-null float64
dtypes: float64(1), int64(3)
memory usage: 2.1 MB
df.describe()
user_idorder_dtorder_productsorder_amount
count69659.0000006.965900e+0469659.00000069659.000000
mean11470.8545921.997228e+072.41004035.893648
std6819.9048483.837735e+032.33392436.281942
min1.0000001.997010e+071.0000000.000000
25%5506.0000001.997022e+071.00000014.490000
50%11410.0000001.997042e+072.00000025.980000
75%17273.0000001.997111e+073.00000043.700000
max23570.0000001.998063e+0799.0000001286.010000
  • 大部分订单只购买了少量商品(平均2.4),50%的订单购买商品数量了在2个及以下,75%的订单购买商品数量在3个及以下,最多的订单购买了99个商品,平均消费商品数量存在一定极值干扰;
  • 订单平均交易金额35元,中位数在25元,75%的订单金额在43元及以下,订单最大金额为1286,有一定极值干扰
df['order_dt']= pd.to_datetime(df.order_dt,format='%Y%m%d')
df['month']=df.order_dt.values.astype('datetime64[M]')
df.head()
user_idorder_dtorder_productsorder_amountmonth
011997-01-01111.771997-01-01
121997-01-12112.001997-01-01
221997-01-12577.001997-01-01
331997-01-02220.761997-01-01
431997-03-30220.761997-03-01

二、用户消费趋势分析

2.1每月消费总金额

grouped_month = df.groupby('month')
order_month_amount = grouped_month.order_amount.sum()
order_month_amount.head()
month
1997-01-01    299060.17
1997-02-01    379590.03
1997-03-01    393155.27
1997-04-01    142824.49
1997-05-01    107933.30
Name: order_amount, dtype: float64
import matplotlib.pyplot as plt
%matplotlib inline
#更改设计风格
plt.style.use('ggplot')
order_month_amount.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x2f08d6c8710>

每月消费总金额

消费金额在前三个月达到最高峰,之后急剧下降,1997年4月份之后每月消费总金额比较平稳,有轻微下降趋势。

2.2每月订单总数

grouped_month.user_id.count().plot()
<matplotlib.axes._subplots.AxesSubplot at 0x2f08da00908>

每月订单总数变化

前三个月订单总数量平均为10000笔左右,后续月份平均每个月的订单量在2500笔左右。

2.3每月消费总产品数

grouped_month.order_products.sum().plot()
<matplotlib.axes._subplots.AxesSubplot at 0x2f08da99da0>

每月消费总产品数

前三个月消费总产品数达到最高峰,平均为24000左右,后续月份平均每月消费产品量约在6000左右。

2.4每月消费总人数

df.groupby('month').user_id.apply(lambda x: len(x.drop_duplicates())).plot()
<matplotlib.axes._subplots.AxesSubplot at 0x2f08db04400>

每月消费总人数

  • 每月消费人数低于每月订单总数(即每月消费次数),但差异不大;
  • 前三个月每月的消费人数在8000-10000人左右,后续月份平均消费人数不足2000。

2.5每月用户平均消费金额

grouped_month.apply( lambda x : x.order_amount.sum() / x.user_id.nunique() ).plot()
<matplotlib.axes._subplots.AxesSubplot at 0x2f091378f60>

每月用户平均消费金额

前三个月平均金额稍低,后续月份每月用户平均消费金额在47-57之间波动,变化不大。

2.6每月用户平均消费次数

grouped_month.apply( lambda x : x.user_id.count() / x.user_id.nunique() ).plot()
<matplotlib.axes._subplots.AxesSubplot at 0x2f092ef2978>

每月用户平均消费次数

  • 每月用户平均消费频次在1.13-1.15之间,前三个月由于用户大量涌入,部分用户可能仅消费了一次,导致频次略低;
  • 后续月份用户平均消费频次比较平稳,且略高于前3个月。
#也可以用数据透视的方法
df.pivot_table(index='month',
               values=['order_products','order_amount','user_id'],
               aggfunc={'order_products':'sum','order_amount':'sum','user_id':'count'}).head()
order_amountorder_productsuser_id
month
1997-01-01299060.17194168928
1997-02-01379590.032492111272
1997-03-01393155.272615911598
1997-04-01142824.4997293781
1997-05-01107933.3072752895

三、用户个体消费分析

grouped_user = df.groupby('user_id')
grouped_user.sum().describe()
order_productsorder_amount
count23570.00000023570.000000
mean7.122656106.080426
std16.983531240.925195
min1.0000000.000000
25%1.00000019.970000
50%3.00000043.395000
75%7.000000106.475000
max1033.00000013990.930000
  • 平均每用户购买了7张CD,但是中位数只有3,说明小部分用户购买了大量CD;
  • 用户平均消费106元,中位值为43,75%分位数为106,刚好等于平均消费,有25%的用户消费的比平均金额多,再看最大消费金额为13990(CD狂热爱好者啊),佐证了上面小部分用户购买了大量CD的结论,数据存在极值干扰。

3.1用户消费金额和消费次数的散点图

grouped_user.sum().query('order_amount<4000').plot.scatter(x='order_amount',y='order_products')
<matplotlib.axes._subplots.AxesSubplot at 0x2f08ecd7898>

用户消费金额和消费次数的散点图1)

可以看到最后面两个极值的存在拉大了图形区域,使得密集区域集中在左下角。通过过滤排除极值干扰:

grouped_user.sum().query('order_products < 350').plot.scatter(x = 'order_products', y = 'order_amount')
<matplotlib.axes._subplots.AxesSubplot at 0x2f095b70550>

用户消费金额和消费次数的散点图2

散点图呈现明显的线性关系,可以推测CD产品比较单一,单价比较稳定。

3.2用户消费金额分布图

grouped_user.sum().order_amount.plot.hist(bins=100)
<matplotlib.axes._subplots.AxesSubplot at 0x2f08ed6b2b0>

用户消费金额分布图1

从直方图可知,用户消费金额,绝大部分呈现集中趋势,大部分用户消费金额在1500以内,小部分异常值干扰了判断。
使用切比雪夫定律(95%的数据位于其平均值+5标准差范围之内)过滤异常值,由3.1的用户消费金额及购买产品数量的描述性统计可知,95%的用户消费金额位于106+5240=1306范围内:

grouped_user.sum().query('order_amount < 1306').order_amount.plot.hist(bins = 20)
<matplotlib.axes._subplots.AxesSubplot at 0x2f09568f748>

用户消费金额分布图2

3.3用户消费次数分布图

# 同上,获取过滤掉极值之后的用户购买产品数量分布:
grouped_user.sum().query('order_products < 100').order_products.plot.hist(bins = 20)
<matplotlib.axes._subplots.AxesSubplot at 0x2f0934cbf60>

用户消费次数分布图

可以看出,大部分用户仅购买了1-5张CD,整体购买数量和消费金额成指数下降趋势。

3.4 用户累计消费金额占比

user_cumsum = grouped_user.sum().sort_values('order_amount').apply(lambda x: x.cumsum()/x.sum())
user_cumsum.reset_index().order_amount.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x2f08efb5908>

用户累计消费金额占比

按用户消费金额进行升序排列,50%的用户仅贡献了约15%的消费额,消费金额排名靠前的20%用户贡献了60%的消费额。

四、用户消费行为分析

4.1用户第一次消费

  • 备注:首购是一个比较重要的维度,它和渠道等息息相关, 尤其是客单价比较高用户留存率又比较低的行业, 可以通过首购分析第一次购买的用户渠道,然后拓展出运营的方式。
  • 通过对用户第一次购买时间最小值的统计获取用户首购时间分布情况:
grouped_user.min().order_dt.value_counts().plot()
<matplotlib.axes._subplots.AxesSubplot at 0x2f08f09c588>

用户第一次消费

用户第一次购买分布集中在前三个月,其中在2月11号至2月15号之间有一次剧烈波动

4.2用户最近一次消费

grouped_user.max().order_dt.value_counts().plot()
<matplotlib.axes._subplots.AxesSubplot at 0x2f08f055ba8>

用户最近一次消费

  • 用户最后一次购买的分布比第一次购买的分布要广;
  • 大部分最后一次购买集中在前三个月,说明很多用户购买了一次后就不再购买;
  • 随着时间的递增,最后一次购买数也在递增,消费呈现流失上升的状况。

4.3新老客消费比

4.3.1多少用户仅消费一次
user_life = grouped_user.order_dt.agg(['min','max'])
user_life.head()
minmax
user_id
11997-01-011997-01-01
21997-01-121997-01-12
31997-01-021998-05-28
41997-01-011997-12-12
51997-01-011998-01-03
(user_life['min']== user_life['max']).value_counts()
True     12054
False    11516
dtype: int64

超过一半用户仅消费了一次

4.3.2每月新客占比
grouped_month_user = df.groupby(['month', 'user_id'])  # 按月和用户ID分组
tmp = grouped_month_user.order_dt.agg(['min']).join(grouped_user.order_dt.min())  # 求出用户在当月首购时间和用户在所有时间段的首购时间
tmp['is_new'] = (tmp['min'] ==  tmp['order_dt'])  # 新增一列,是否首购时间在当月,即是否为新客
tmp.reset_index().groupby('month').apply(lambda x : x.is_new.sum() / x.user_id.count() ).plot()  # 计算新客占比
<matplotlib.axes._subplots.AxesSubplot at 0x2f08f10d780>

每月新客占比

新客集中在前三个月,后面消费的均为老用户。

4.4用户分层

R:最近一次消费时间
F:消费频率
M:消费金额

rfm = df.pivot_table(index = 'user_id',
                     values = ['order_products','order_amount','order_dt'],
                     aggfunc = {'order_products':'sum','order_amount':'sum','order_dt':'max'})
rfm.head()
order_amountorder_dtorder_products
user_id
111.771997-01-011
289.001997-01-126
3156.461998-05-2816
4100.501997-12-127
5385.611998-01-0329
rfm['R'] = -(rfm.order_dt - rfm.order_dt.max()) / np.timedelta64(1,'D')
rfm.rename(columns = {'order_products':'F','order_amount':'M'},inplace = True)
def rfm_func(x):
    level = x.apply(lambda x:'1' if x>1 else '0')
    label = level.R + level.F + level.M
    d = {
        '111':'重要价值客户',
        '011':'重要保持客户',
        '101':'重要发展客户',
        '001':'重要挽留客户',
        '110':'一般价值客户',
        '010':'一般保持客户',
        '100':'一般发展客户',
        '000':'一般挽留客户'
    }
    result = d[label]
    return result
rfm['label'] = rfm[['R','F','M']].apply(lambda x:x - x.mean()).apply(rfm_func,axis = 1)
#将用户在R、F、M三个维度上分为低于平均额度和高于平均额度的用户(划分标准根据不同业务设计不同):
rfm.groupby('label').sum()
MFR
label
一般价值客户1767.111828512.0
一般保持客户5100.774927782.0
一般发展客户445233.28299156983699.0
一般挽留客户215075.7715428621894.0
重要价值客户147180.099849286676.0
重要保持客户1555586.51105509476502.0
重要发展客户49905.802322174340.0
重要挽留客户80466.30418496009.0
rfm.groupby('label').count()
Morder_dtFRcolor
label
一般价值客户1818181818
一般保持客户5353535353
一般发展客户1413814138141381413814138
一般挽留客户34933493349334933493
重要价值客户631631631631631
重要保持客户42674267426742674267
重要发展客户371371371371371
重要挽留客户599599599599599

从RFM分层结果可知,“重要保持客户”为主要利润来源,即最后一次消费时间越晚,消费频次越高,消费额度越高的用户是优质客户。

rfm.loc[ rfm.label == '重要保持客户', 'color'] = 'brown'
rfm.loc[ rfm.label == '重要发展客户', 'color'] = 'grey'
rfm.loc[ rfm.label == '重要价值客户', 'color'] = 'c'
rfm.loc[ rfm.label == '重要挽留客户', 'color'] = 'r'
rfm.loc[ rfm.label == '一般保持客户', 'color'] = 'k'
rfm.loc[ rfm.label == '一般发展客户', 'color'] = 'y'
rfm.loc[ rfm.label == '一般价值客户', 'color'] = 'm'
rfm.loc[ rfm.label == '一般挽留客户', 'color'] = 'w'

rfm.plot.scatter('F', 'R', c=rfm.color)
<matplotlib.axes._subplots.AxesSubplot at 0x2f090f08cf8>

不同标签客户分布

从图中可以看到大部分用户的购买频次在200以内,少部分的极值可能会对我们使用平均值划分RFM造成一定程度的偏差(平均值对大部分用户来说偏大),所以如果使用平均值划分应该考虑到先根据切比雪夫定律剔除极值

4.5用户生命周期分析

pivoted_counts = df.pivot_table(index = 'user_id',
                                columns = 'month',
                                values = 'order_dt',
                                aggfunc = 'count').fillna(0)
pivoted_counts.head()
month1997-01-01 00:00:001997-02-01 00:00:001997-03-01 00:00:001997-04-01 00:00:001997-05-01 00:00:001997-06-01 00:00:001997-07-01 00:00:001997-08-01 00:00:001997-09-01 00:00:001997-10-01 00:00:001997-11-01 00:00:001997-12-01 00:00:001998-01-01 00:00:001998-02-01 00:00:001998-03-01 00:00:001998-04-01 00:00:001998-05-01 00:00:001998-06-01 00:00:00
user_id
11.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.0
22.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.0
31.00.01.01.00.00.00.00.00.00.02.00.00.00.00.00.01.00.0
42.00.00.00.00.00.00.01.00.00.00.01.00.00.00.00.00.00.0
52.01.00.01.01.01.01.00.01.00.00.02.01.00.00.00.00.00.0
df_purchase = pivoted_counts.applymap(lambda x: 1 if x>0 else 0)
df_purchase.tail()
month1997-01-01 00:00:001997-02-01 00:00:001997-03-01 00:00:001997-04-01 00:00:001997-05-01 00:00:001997-06-01 00:00:001997-07-01 00:00:001997-08-01 00:00:001997-09-01 00:00:001997-10-01 00:00:001997-11-01 00:00:001997-12-01 00:00:001998-01-01 00:00:001998-02-01 00:00:001998-03-01 00:00:001998-04-01 00:00:001998-05-01 00:00:001998-06-01 00:00:00
user_id
23566001000000000000000
23567001000000000000000
23568001100000000000000
23569001000000000000000
23570001000000000000000
def active_status(data):
    status = []
    for i in range(18):
        
        #若本月没有消费
        if data[i] == 0:
            if len(status) > 0:
                if status[i-1] == 'unreg':
                    status.append('unreg')
                else:
                    status.append('unactive')
            else:
                status.append('unreg')
        
        #若本月消费
        else:
            if len(status) == 0:
                status.append('new')
            else:
                if status[i-1] == 'unactive':
                    status.append('return')
                elif status[i-1] == 'unreg':
                    status.append('new')
                else:
                    status.append('active')
    return status

函数逻辑:
若本月没有消费

  • 若之前是未注册,则依旧为未注册
  • 若之前有消费,则为流失/不活跃
  • 其他情况,为未注册

若本月有消费

  • 若为第一次消费,则为新用户
  • 若果之前有过消费,则上个月为不活跃,则为回流
  • 如果上个月为未注册,则为新用户
  • 除此之外,为活跃
indexs=df['month'].sort_values().astype('str').unique()
purchase_stats = df_purchase.apply(lambda x:pd.Series(active_status(x),index=indexs),axis=1)
purchase_stats.head()
1997-01-011997-02-011997-03-011997-04-011997-05-011997-06-011997-07-011997-08-011997-09-011997-10-011997-11-011997-12-011998-01-011998-02-011998-03-011998-04-011998-05-011998-06-01
user_id
1newunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactive
2newunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactiveunactive
3newunactivereturnactiveunactiveunactiveunactiveunactiveunactiveunactivereturnunactiveunactiveunactiveunactiveunactivereturnunactive
4newunactiveunactiveunactiveunactiveunactiveunactivereturnunactiveunactiveunactivereturnunactiveunactiveunactiveunactiveunactiveunactive
5newactiveunactivereturnactiveactiveactiveunactivereturnunactiveunactivereturnactiveunactiveunactiveunactiveunactiveunactive
purchase_stats_ct = purchase_stats.replace('unreg',np.NaN).apply(lambda x: pd.value_counts(x))
purchase_stats_ct
1997-01-011997-02-011997-03-011997-04-011997-05-011997-06-011997-07-011997-08-011997-09-011997-10-011997-11-011997-12-011998-01-011998-02-011998-03-011998-04-011998-05-011998-06-01
activeNaN1157.016811773.0852.0747.0746.0604.0528.0532.0624.0632.0512.0472.0571.0518.0459.0446.0
new7846.08476.07248NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
returnNaNNaN5951049.01362.01592.01434.01168.01211.01307.01404.01232.01025.01079.01489.0919.01029.01060.0
unactiveNaN6689.01404620748.021356.021231.021390.021798.021831.021731.021542.021706.022033.022019.021510.022133.022082.022064.0
purchase_stats_ct.fillna(0).T.head()
activenewreturnunactive
1997-01-010.07846.00.00.0
1997-02-011157.08476.00.06689.0
1997-03-011681.07248.0595.014046.0
1997-04-011773.00.01049.020748.0
1997-05-01852.00.01362.021356.0
purchase_stats_ct.fillna(0).T.plot.area()
<matplotlib.axes._subplots.AxesSubplot at 0x2f09297e0f0>

用户生命周期

由图可知,到了在前三个月,新用户增加的数量非常大。从三月一号开始,用户开始快速流失。到后面的几个月流失用户基本占绝大比例。

purchase_stats_ct.fillna(0).T.apply(lambda x:x/x.sum(),axis=1)
activenewreturnunactive
1997-01-010.0000001.0000000.0000000.000000
1997-02-010.0708860.5192990.0000000.409815
1997-03-010.0713190.3075100.0252440.595927
1997-04-010.0752230.0000000.0445060.880272
1997-05-010.0361480.0000000.0577850.906067
1997-06-010.0316930.0000000.0675430.900764
1997-07-010.0316500.0000000.0608400.907510
1997-08-010.0256260.0000000.0495550.924820
1997-09-010.0224010.0000000.0513790.926220
1997-10-010.0225710.0000000.0554520.921977
1997-11-010.0264740.0000000.0595670.913958
1997-12-010.0268140.0000000.0522700.920916
1998-01-010.0217230.0000000.0434870.934790
1998-02-010.0200250.0000000.0457790.934196
1998-03-010.0242260.0000000.0631740.912601
1998-04-010.0219770.0000000.0389900.939033
1998-05-010.0194740.0000000.0436570.936869
1998-06-010.0189220.0000000.0449720.936105

由上表可知,每月的用户消费状态变化

  • 活跃用户,持续消费的用户,对应的是消费运营的质量
  • 回流用户,之前不消费,本月才消费,对应的是换回运营
  • 不活跃用户,对应的是流失
order_diff = grouped_user.apply(lambda x:x.order_dt - x.order_dt.shift())
order_diff.head(10)
user_id   
1        0        NaT
2        1        NaT
         2     0 days
3        3        NaT
         4    87 days
         5     3 days
         6   227 days
         7    10 days
         8   184 days
4        9        NaT
Name: order_dt, dtype: timedelta64[ns]
order_diff.describe()
count                      46089
mean     68 days 23:22:13.567662
std      91 days 00:47:33.924168
min              0 days 00:00:00
25%             10 days 00:00:00
50%             31 days 00:00:00
75%             89 days 00:00:00
max            533 days 00:00:00
Name: order_dt, dtype: object
(order_diff/np.timedelta64('1','D')).hist(bins=20)
<matplotlib.axes._subplots.AxesSubplot at 0x2f090431940>

订单周期分布

  • 订单周期呈指数分布
  • 用户的平均购买周期是28天
  • 绝大部分用户的购买周期都低于100天
(user_life['max'] - user_life['min']).describe()
count                       23570
mean     134 days 20:55:36.987696
std      180 days 13:46:43.039788
min               0 days 00:00:00
25%               0 days 00:00:00
50%               0 days 00:00:00
75%             294 days 00:00:00
max             544 days 00:00:00
dtype: object
((user_life['max'] - user_life['min'])/np.timedelta64('1','D')).hist(bins=40)
<matplotlib.axes._subplots.AxesSubplot at 0x2f093b8ca58>

在这里插入图片描述

#过滤掉零值
u_1 = (user_life['max'] - user_life['min'])/np.timedelta64('1','D')
u_1[u_1>0].hist(bins=40)
<matplotlib.axes._subplots.AxesSubplot at 0x2f090d3fc18>

在这里插入图片描述

  • 用户的生命周期受只够买一次的用户的影响比较厉害(可以排除)
  • 用户均消费134天,中位数仅0天

五、复购率和回购率分析

pivoted_counts.head()
month1997-01-01 00:00:001997-02-01 00:00:001997-03-01 00:00:001997-04-01 00:00:001997-05-01 00:00:001997-06-01 00:00:001997-07-01 00:00:001997-08-01 00:00:001997-09-01 00:00:001997-10-01 00:00:001997-11-01 00:00:001997-12-01 00:00:001998-01-01 00:00:001998-02-01 00:00:001998-03-01 00:00:001998-04-01 00:00:001998-05-01 00:00:001998-06-01 00:00:00
user_id
11.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.0
22.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.0
31.00.01.01.00.00.00.00.00.00.02.00.00.00.00.00.01.00.0
42.00.00.00.00.00.00.01.00.00.00.01.00.00.00.00.00.00.0
52.01.00.01.01.01.01.00.01.00.00.02.01.00.00.00.00.00.0
purchase_r = pivoted_counts.applymap(lambda x: 1 if x>1 else np.NaN if x==0 else 0)
purchase_r.head()
month1997-01-01 00:00:001997-02-01 00:00:001997-03-01 00:00:001997-04-01 00:00:001997-05-01 00:00:001997-06-01 00:00:001997-07-01 00:00:001997-08-01 00:00:001997-09-01 00:00:001997-10-01 00:00:001997-11-01 00:00:001997-12-01 00:00:001998-01-01 00:00:001998-02-01 00:00:001998-03-01 00:00:001998-04-01 00:00:001998-05-01 00:00:001998-06-01 00:00:00
user_id
10.0NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
21.0NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
30.0NaN0.00.0NaNNaNNaNNaNNaNNaN1.0NaNNaNNaNNaNNaN0.0NaN
41.0NaNNaNNaNNaNNaNNaN0.0NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
51.00.0NaN0.00.00.00.0NaN0.0NaNNaN1.00.0NaNNaNNaNNaNNaN

5.1复购率(自然月内购买多次的用户占比)

(purchase_r.sum()/purchase_r.count()).plot(figsize=(10,4))
<matplotlib.axes._subplots.AxesSubplot at 0x2f09130db38>

在这里插入图片描述

复购率在前三个月高速增长,主要因为前三个月大量新用户涌入,而这批用户只购买了一次,导致复购率低,最终在大概四月份的时候稳定在20%左右

5.2回购率(曾经购买过的用户在某一时期内的再次购买的占比)

df_purchase = df_purchase.fillna(0)
df_purchase.head()
month1997-01-01 00:00:001997-02-01 00:00:001997-03-01 00:00:001997-04-01 00:00:001997-05-01 00:00:001997-06-01 00:00:001997-07-01 00:00:001997-08-01 00:00:001997-09-01 00:00:001997-10-01 00:00:001997-11-01 00:00:001997-12-01 00:00:001998-01-01 00:00:001998-02-01 00:00:001998-03-01 00:00:001998-04-01 00:00:001998-05-01 00:00:001998-06-01 00:00:00
user_id
1100000000000000000
2100000000000000000
3101100000010000010
4100000010001000000
5110111101001100000
def purchase_back(data):
    status=[]
    for i in range(17):
        if data[i]==1:
            if data[i+1]==1:
                status.append(1)
            if data[i+1]==0:
                status.append(0)
        else:
            status.append(np.NaN)
    status.append(np.NaN)
    return status
#purchase_b = df_purchase.apply(purchase_back,axis=1)
indexs=df['month'].sort_values().astype('str').unique()
purchase_b = df_purchase.apply(lambda x:pd.Series(purchase_back(x),index=indexs),axis=1)
purchase_b.head()
1997-01-011997-02-011997-03-011997-04-011997-05-011997-06-011997-07-011997-08-011997-09-011997-10-011997-11-011997-12-011998-01-011998-02-011998-03-011998-04-011998-05-011998-06-01
user_id
10.0NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
20.0NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
30.0NaN1.00.0NaNNaNNaNNaNNaNNaN0.0NaNNaNNaNNaNNaN0.0NaN
40.0NaNNaNNaNNaNNaNNaN0.0NaNNaNNaN0.0NaNNaNNaNNaNNaNNaN
51.00.0NaN1.01.01.00.0NaN0.0NaNNaN1.00.0NaNNaNNaNNaNNaN
(purchase_b.sum()/purchase_b.count()).plot(figsize=(10,4))
<matplotlib.axes._subplots.AxesSubplot at 0x2f093343b00>

在这里插入图片描述

可以看出,回购率在前三个月快速增长,知道四月份增长到30%以后,一直维持在30%左右波动

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值