淘宝用户行为分析

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
import warnings 
warnings.filterwarnings('ignore')
df = pd.read_csv(r'C:\Users\zcy\Desktop\淘宝用户分析\tianchi_mobile_recommend_train_user.csv') 
df.head()
user_iditem_idbehavior_typeuser_geohashitem_categorytime
0980478372324315621NaN42452014-12-06 02
1977261363835835901NaN58942014-12-09 20
298607707647497121NaN28832014-12-18 11
398662432320593836196nn52n65622014-12-06 10
4981459082902085201NaN139262014-12-16 21
#对时间特征处理,添加每日时间段,星期特征
df.time = pd.to_datetime(df['time']) 
df['daily'] = df['time'].dt.hour
df['weekday'] = df['time'].dt.weekday
df['date'] = df['time'].dt.date
df.head()
user_iditem_idbehavior_typeuser_geohashitem_categorytimedailyweekdaydate
0980478372324315621NaN42452014-12-06 02:00:00252014-12-06
1977261363835835901NaN58942014-12-09 20:00:002012014-12-09
298607707647497121NaN28832014-12-18 11:00:001132014-12-18
398662432320593836196nn52n65622014-12-06 10:00:001052014-12-06
4981459082902085201NaN139262014-12-16 21:00:002112014-12-16
df.drop(columns='user_geohash',axis=1,inplace=True)
behavior = {1:'pv',2:'collect',3:'cart',4:'buy'}
df['behavior_type'] = df['behavior_type'].replace(behavior)
df.head()
user_iditem_idbehavior_typeitem_categorytimedailyweekdaydate
098047837232431562pv42452014-12-06 02:00:00252014-12-06
197726136383583590pv58942014-12-09 20:00:002012014-12-09
29860770764749712pv28832014-12-18 11:00:001132014-12-18
398662432320593836pv65622014-12-06 10:00:001052014-12-06
498145908290208520pv139262014-12-16 21:00:002112014-12-16

数据分析

1.时间维度上的整体分析
2.用户行为路径分析(用户消费行为)
3.留存率与活跃度分析
4.用户分类分析

1.时间维度上的整体分析

b = df.groupby(['daily','behavior_type'])['user_id'].agg('count').reset_index().rename(columns={'user_id':'num'})
b
dailybehavior_typenum
00buy4845
10cart14156
20collect11062
30pv487341
41buy1703
............
9122pv1027269
9223buy6359
9323cart27434
9423collect17705
9523pv797754

96 rows × 3 columns

table_time = df.groupby(['daily','behavior_type'])['user_id'].agg('count').unstack()
table_time
behavior_typebuycartcollectpv
daily
048451415611062487341
1170367126276252991
280638343311139139
35042480228293250
43972248201075832
54762213206283545
6102337683651150356
7193870445885272470
8358699707849374701
957071295610507456781
1073171620311185515960
1170861525710918493679
126956150259940500036
1377171741911694561513
1472071706711695558246
1573121728912010562238
1669301630411127541846
175298145159754476369
1851401482310342517078
1963521885313952696035
2078722502116599885669
21882930469203971030483
22884532504203431027269
2363592743417705797754
table_time.columns
Index(['buy', 'cart', 'collect', 'pv'], dtype='object', name='behavior_type')
table_time.plot.bar(figsize=(10,5))
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['savefig.dpi'] = 300  # 图片像素
plt.rcParams['figure.dpi'] = 300  # 分辨率
plt.rcParams['figure.figsize'] = (15.0, 8.0)  # 尺寸

在这里插入图片描述

from pyecharts import options as opts
from pyecharts.charts import Bar

c = (
    Bar()
    .add_xaxis(list(table_time.index)
            
    )
    .add_yaxis("buy", list(table_time.buy))
    .add_yaxis("cart", list(table_time.cart))
    .add_yaxis("collect", list(table_time.collect))
    .add_yaxis("pv", list(table_time.pv))
    .set_global_opts(
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),
        title_opts=opts.TitleOpts(title="24小时的用户行为"),
    )
    .render("bar_daily.html")
)
table_time.plot.bar(y=['buy', 'cart', 'collect'],figsize=(10,5))

在这里插入图片描述

随着一天从6点开始,人们逐渐开始逛淘宝,而且白天用户行为相对稳定,到了晚上5-6点用户行为激增并且一直持续到晚上十一点之前,表明在晚上是用户发生用户行为的高峰期。但是点击、收藏、加入购物车的数量都在晚上存在明显的提升,相对而言在购买上晚上的提升没有其他用户行为显著。
推测用户应该是在晚上有充足的时间进行浏览,并不会立刻下单购买,直到白天经过一晚上思索产生了购买行为,又或者是企业方面的购买需求在白天工作期间我完成

table_date = df.groupby(['date','behavior_type'])['user_id'].agg('count').unstack()
table_date
behavior_typebuycartcollectpv
date
2014-11-183730102126904345855
2014-11-193686101157152337870
2014-11-203462100087167332792
2014-11-21302186796832314572
2014-11-22357099707252340563
2014-11-233347104327702361221
2014-11-243426103917333357192
2014-11-25346498917492349392
2014-11-26357393787324340621
2014-11-27367099757699350040
2014-11-28321891236484321813
2014-11-293211101457214344127
2014-11-303616107797786379439
2014-12-013909112887319372095
2014-12-023621115218022382052
2014-12-033885117328492387497
2014-12-043691113958559376307
2014-12-053319101097474340976
2014-12-063272108898323367126
2014-12-073256112678632376596
2014-12-083419109158236364097
2014-12-093449117638552374261
2014-12-103216122808753397661
2014-12-113226156439310460329
2014-12-12152512450810446641507
2014-12-133478104867859385337
2014-12-143483102138128380717
2014-12-153764102107758376624
2014-12-163771101667749373399
2014-12-173615102567163363757
2014-12-18358698257440354746
table_date.plot(rot=45,figsize=(10,5))

在这里插入图片描述

table_date.plot(y=['buy', 'cart', 'collect'],figsize=(10,5),rot=45)

在这里插入图片描述

d = df[df.date.astype('str')=='2014-12-12'].groupby(['daily','behavior_type'])['user_id'].agg('count').unstack()
d.plot.bar(figsize=(10,5),rot=0)

在这里插入图片描述

d.plot.bar(y=['buy', 'cart', 'collect'],figsize=(10,5),rot=0)
plt.xlabel('双十二')

在这里插入图片描述

可以明显的看出,在双十二前三天,用户点击以及加入购物车的行为已经开始升高,说明对双十二的各种宣传已经开始,但在当时的背景下,人们对网购的热情远没有现在这样狂热,而且当时促销手段也没有像现在这样各种预售、游戏、抢优惠券等模式多样化,因此购买行为全部在双十二当天完成。
在当时的背景下,应该着重关注活动期间的数据变化,针对整个活动,从初期预热的点击到加购物车转化率,到双十二当天的购买率等,为运营提供建议

table_week = df.groupby(['weekday','behavior_type'])['user_id'].agg('count').unstack()
table_week.index = table_week.index +1
table_week
behavior_typebuycartcollectpv
weekday
11451842804306461470008
21803553553387191824959
31797553761388841827406
41763556846401751874214
52480952419312361618868
61353141490306481437153
71370242691322481497973
table_week.plot.bar(figsize=(10,5),rot=0)
#plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
#plt.rcParams['savefig.dpi'] = 300  # 图片像素
#plt.rcParams['figure.dpi'] = 300  # 分辨率
#plt.rcParams['figure.figsize'] = (15.0, 8.0)  # 尺寸

在这里插入图片描述

table_week.plot.bar(y=['buy', 'cart', 'collect'],figsize=(10,5),rot=0)

在这里插入图片描述

从图中得到用户行为在工作日比休息日要高,推测可能是因为当时背景下,人们的购物行为还是以逛街去实体店为主,而在工作日则多以收藏加购物车为主,周末则去实体店进行购买。为了扭转这种局面,应该加大推广力度,打消人们对网上购物的不信任感。而周五的购买行为升高和双十二为周五有关,并不具备代表性。

从时间维度,我们能得到以下几点:
1.人们在晚上7点到11点空闲时间多为浏览收藏加购物的行为,应加强推送力度以及精确度
2.双十二活动明显改变用户行为,用户在活动开始前浏览收藏加入购物车行为猛增,而活动当天购买行为提升
3.工作日用户行为比休息日要高,这可能和当时背景有关

2.用户行为路径分析(用户消费行为)

table_time = df.groupby(['daily','behavior_type'])['user_id'].agg('count').unstack()
table_time
behavior_typebuycartcollectpv
daily
048451415611062487341
1170367126276252991
280638343311139139
35042480228293250
43972248201075832
54762213206283545
6102337683651150356
7193870445885272470
8358699707849374701
957071295610507456781
1073171620311185515960
1170861525710918493679
126956150259940500036
1377171741911694561513
1472071706711695558246
1573121728912010562238
1669301630411127541846
175298145159754476369
1851401482310342517078
1963521885313952696035
2078722502116599885669
21882930469203971030483
22884532504203431027269
2363592743417705797754
trans = []
for i in range(len(table_time.index)):
    pv2collect = table_time.collect[i]/table_time.pv[i]
    pv2cart = table_time.cart[i]/table_time.pv[i]
    pv2tobuy = (table_time.collect[i]+table_time.cart[i])/table_time.pv[i]
    pv2buy = table_time.buy[i]/table_time.pv[i]
    tobuy2buy = table_time.buy[i]/(table_time.collect[i]+table_time.cart[i])
    collect2buy = table_time.buy[i]/table_time.collect[i]
    cart2buy = table_time.buy[i]/table_time.cart[i]
    tran = [pv2collect,pv2cart,pv2tobuy,pv2buy,tobuy2buy,collect2buy,cart2buy]
    trans.append(tran)
data = pd.DataFrame(data=trans,index=table_time.index,columns=['pv2collect','pv2cart','pv2tobuy','pv2buy','tobuy2buy','collect2buy','cart2buy'])
data
pv2collectpv2cartpv2tobuypv2buytobuy2buycollect2buycart2buy
daily
00.0226990.0290470.0517460.0099420.1921250.4379860.342258
10.0248070.0265310.0513380.0067310.1311210.2713510.253725
20.0237960.0275550.0513520.0057930.1128060.2434310.210224
30.0244720.0265950.0510670.0054050.1058380.2208590.203226
40.0265060.0296440.0561500.0052350.0932360.1975120.176601
50.0246810.0264890.0511700.0056980.1113450.2308440.215093
60.0242820.0250610.0493430.0068040.1378890.2801970.271497
70.0215990.0258520.0474510.0071130.1498960.3293120.275128
80.0209470.0266080.0475550.0095700.2012460.4568730.359679
90.0230020.0283640.0513660.0124940.2432340.5431620.440491
100.0216780.0314040.0530820.0141810.2671610.6541800.451583
110.0221160.0309050.0530200.0143530.2707160.6490200.464443
120.0198790.0300480.0499260.0139110.2786300.6997990.462962
130.0208260.0310220.0518470.0137430.2650710.6599110.443022
140.0209500.0305730.0515220.0129100.2505740.6162460.422277
150.0213610.0307500.0521110.0130050.2495650.6088260.422928
160.0205350.0300900.0506250.0127900.2526340.6228090.425049
170.0204760.0304700.0509460.0111220.2183030.5431620.365002
180.0200010.0286670.0486680.0099400.2042520.4970030.346758
190.0200450.0270860.0471310.0091260.1936290.4552750.336923
200.0187420.0282510.0469930.0088880.1891400.4742450.314616
210.0197940.0295680.0493610.0085680.1735740.4328580.289770
220.0198030.0316410.0514440.0086100.1673700.4347930.272120
230.0221940.0343890.0565830.0079710.1408760.3591640.231793
data.plot()

在这里插入图片描述

data.plot(y=['pv2tobuy','tobuy2buy'],xticks=data.index.values)

在这里插入图片描述

加收藏和加购物车没有明显的逻辑关系,将加收藏和加购物车当做一类行为,即有购买倾向行为。
从图中可以看出点击行为到购买倾向行为和一天中时间没有太大关系,而购买倾向行为到购买行为,从早上7点开始逐渐增多,直到12点到达顶峰,然后开始下降直到晚上,在白天工作期间一方面可能是企业需求进行购买,应该关注如何快速准确满足企业需求;另一方面可能是晚上经过思考到了白天产生购买行为,应该加大收藏或加入购物车商品的营销,如给与优惠券、提醒优惠时间期限、提醒降价等等

data.plot(y=['pv2collect','pv2cart','pv2tobuy','pv2buy'],xticks=data.index.values)

在这里插入图片描述

从图中可以看出,购买行为如之前分析大都发生在白天,而从浏览行为到购买倾向行为的转化,都在晚上19点之后有明显的提升,这样一方面需要加大商品推送力度,另一方面需要加大对用户购买行为的挖掘、进行个性化推荐,从而增强用户粘性和活跃度

data.plot(y=['tobuy2buy','collect2buy','cart2buy'],xticks=data.index.values)

在这里插入图片描述

trans1 = []
for i in range(len(table_date.index)):
    pv2collect = table_date.collect[i]/table_date.pv[i]
    pv2cart = table_date.cart[i]/table_date.pv[i]
    pv2tobuy = (table_date.collect[i]+table_date.cart[i])/table_date.pv[i]
    pv2buy = table_date.buy[i]/table_date.pv[i]
    tobuy2buy = table_date.buy[i]/(table_date.collect[i]+table_date.cart[i])
    collect2buy = table_date.buy[i]/table_date.collect[i]
    cart2buy = table_date.buy[i]/table_date.cart[i]
    tran = [pv2collect,pv2cart,pv2tobuy,pv2buy,tobuy2buy,collect2buy,cart2buy]
    trans1.append(tran)
data = pd.DataFrame(data=trans1,index=table_date.index,columns=['pv2collect','pv2cart','pv2tobuy','pv2buy','tobuy2buy','collect2buy','cart2buy'])
data.plot()

在这里插入图片描述

data.plot(y=['pv2collect','pv2cart','pv2tobuy','pv2buy'])

在这里插入图片描述

图中从浏览到收藏的转化,在双12有明显的下降,而且之后大家的收藏、加购物车行为比之前也要低,这时候人们消费欲望经过双12释放会进入一段疲软期,可以适当减少运营活动次数,从而降低成本

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值