CDNow曾经是一家在线音乐零售平台,后被德国波泰尔斯曼娱乐集团公司出资收购,其资产总价值在最辉煌时曾超过10亿美元。本文主要通过分析CDNow网站的用户购买明细来分析该网站的用户消费行为,使运营部门在营销时更加具有针对性,从而节省成本,提升效率。
数据来源
本次分析数据来源CDNow网站的用户在1997年1月1日至1998年6月30日期间内购买CD交易明细。
数据下载地址
——提取码: va7h
数据集一共有用户ID,购买日期,订单数,订单金额四个字段。
import numpy as np
import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
columns=['user_id','order_dt','order_products','order_amount']
data=pd.read_table('./CDNOW_master.txt',names=columns,sep='\s+')
data.head()
|
user_id |
order_dt |
order_products |
order_amount |
0 |
1 |
19970101 |
1 |
11.77 |
1 |
2 |
19970112 |
1 |
12.00 |
2 |
2 |
19970112 |
5 |
77.00 |
3 |
3 |
19970102 |
2 |
20.76 |
4 |
3 |
19970330 |
2 |
20.76 |
data.describe()
|
user_id |
order_dt |
order_products |
order_amount |
count |
69659.000000 |
6.965900e+04 |
69659.000000 |
69659.000000 |
mean |
11470.854592 |
1.997228e+07 |
2.410040 |
35.893648 |
std |
6819.904848 |
3.837735e+03 |
2.333924 |
36.281942 |
min |
1.000000 |
1.997010e+07 |
1.000000 |
0.000000 |
25% |
5506.000000 |
1.997022e+07 |
1.000000 |
14.490000 |
50% |
11410.000000 |
1.997042e+07 |
2.000000 |
25.980000 |
75% |
17273.000000 |
1.997111e+07 |
3.000000 |
43.700000 |
max |
23570.000000 |
1.998063e+07 |
99.000000 |
1286.010000 |
从上可知,看数据6关键指标:样本数:69659,最小值:0,最大值:1286,平均值:36,方差36,中位数:26。平均数大于中位数,右偏分布。没有空缺数据,不用清理直接分析,注意到日期数据是整数型,需要转换成时间格式。
data['order_date']=pd.to_datetime(data.order_dt,format='%Y%m%d')
data['month']=data.order_date.values.astype('datetime64[M]')
user_grouped=data.groupby('user_id').sum()
user_grouped
|
order_dt |
order_products |
order_amount |
user_id |
|
|
|
1 |
19970101 |
1 |
11.77 |
2 |
39940224 |
6 |
89.00 |
3 |
119833602 |
16 |
156.46 |
4 |
79882233 |
7 |
100.50 |
5 |
219686137 |
29 |
385.61 |
6 |
19970101 |
1 |
20.99 |
7 |
59921434 |
18 |
264.67 |
8 |
159775420 |
18 |
197.66 |
9 |
59921222 |
6 |
95.85 |
10 |
19970121 |
3 |
39.31 |
11 |
79890766 |
4 |
58.55 |
12 |
19970101 |
4 |
57.06 |
13 |
19970101 |
4 |
72.94 |
14 |
19970101 |
2 |
29.92 |
15 |
19970101 |
4 |
52.87 |
16 |
79882450 |
8 |
79.87 |
17 |
19970101 |
5 |
73.22 |
18 |
19970104 |
1 |
14.96 |
19 |
39940711 |
11 |
175.12 |
20 |
39940219 |
46 |
653.01 |
21 |
39940214 |
4 |
75.11 |
22 |
19970101 |
1 |
14.37 |
23 |
19970101 |
2 |
24.74 |
24 |
39950221 |
4 |
57.77 |
25 |
159804813 |
12 |
137.53 |
26 |
39940227 |
6 |
102.69 |
27 |
39940219 |
10 |
135.87 |
28 |
59910536 |
7 |
90.99 |
29 |
239656335 |
28 |
435.81 |
30 |
39940315 |
2 |
28.34 |
... |
... |
... |
... |
23541 |
39940727 |
2 |
57.34 |
23542 |
19970325 |
5 |
77.43 |
23543 |
19970325 |
2 |
50.76 |
23544 |
59920964 |
12 |
134.63 |
23545 |
19970325 |
1 |
24.99 |
23546 |
19970325 |
1 |
13.97 |
23547 |
39940732 |
2 |
23.54 |
23548 |
19970325 |
2 |
23.54 |
23549 |
19970325 |
2 |
27.13 |
23550 |
19970325 |
2 |
25.28 |
23551 |
119824382 |
12 |
264.63 |
23552 |
39940728 |
4 |
49.38 |
23553 |
39940653 |
8 |
98.58 |
23554 |
39950526 |
3 |
36.37 |
23555 |
99873685 |
14 |
189.18 |
23556 |
139814017 |
15 |
203.00 |
23557 |
19970325 |
1 |
14.37 |
23558 |
79891692 |
11 |
145.60 |
23559 |
59911470 |
8 |
111.65 |
23560 |
19970325 |
1 |
18.36 |
23561 |
59930982 |
6 |
83.46 |
23562 |
19970325 |
2 |
29.33 |
23563 |
39941329 |
3 |
58.75 |
23564 |
59911976 |
5 |
70.01 |
23565 |
19970325 |
1 |
11.77 |
23566 |
19970325 |
2 |
36.00 |
23567 |
19970325 |
1 |
20.97 |
23568 |
59911152 |
6 |
121.70 |
23569 |
19970325 |
2 |
25.74 |
23570 |
39940651 |
5 |
94.08 |
23570 rows × 3 columns
user_grouped.describe()
|
order_dt |
order_products |
order_amount |
count |
2.357000e+04 |
23570.000000 |
23570.000000 |
mean |
5.902627e+07 |
7.122656 |
106.080426 |
std |
9.460684e+07 |
16.983531 |
240.925195 |
min |
1.997010e+07 |
1.000000 |
0.000000 |
25% |
1.997021e+07 |
1.000000 |
19.970000 |
50% |
1.997032e+07 |
3.000000 |
43.395000 |
75% |
5.992125e+07 |
7.000000 |
106.475000 |
max |
4.334408e+09 |
1033.000000 |
13990.930000 |
原表只按订单来记录,现按用户分组看数据集概述。
从购买数量(单位:PC)角度看,用户数量:23570,平均值购买7张,最多购买1033张,属于狂热用户,中位数3张,平均值大于中位数,是右偏分布,存在小部分购买多张碟的用户。
从消费金额(单位:美元)角度看,平均数106,最高值:13990,属于土豪用户,中位数43,平均值大于中位数,是右偏分布,存在小部分高消费用户。
plt.style.use('ggplot')
plt.rcParams['font.sans-serif']=['SimHei']
ax=data.groupby('month').order_products.sum().plot()
ax.set_xlabel('月份')
ax.set_ylabel('数量(张)')
ax.set_title('不同月份的用户购买数量')
plt.show()
ax=data.groupby('month').order_amount.sum().plot()
ax.set_xlabel('月份')
ax.set_ylabel('消费金额')
ax.set_title('不同月份的用户消费金额')
plt.show()
由图片可知,无论是消费金额还是CD碟数都呈现相同的趋势,而且前三月数据都呈现出异常状态,由于我们不知道原数据到底从何获得,只能做出这三个月有促销活动,抑或是这是新开的店之类的,前三个月大多都是新人之类的假设,我们不得而知,继续往下看。
ax=data.groupby('user_id').sum().plot.scatter('order_amount','order_products')
ax.set_xlabel('消费金额')
ax.set_ylabel('数量')
ax.set_title('每个用户消费金额与购买个数的关系')
plt.show()
每个用户的消费金额跟购买数量呈现一定的线性关系。
plt.figure(figsize=(12,4))
ax=plt.subplot(121)
ax=data.groupby('user_id').order_products.sum().plot.hist(bins