数据分析步骤及分析报告练习
这是第一次在博客上发东西,练习练习.是关于一个电商平台的部分数据分析,只是练习,再无他用。
数据分析需要用到库
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime
from matplotlib import font_manager
读入数据
df=pd.read_excel(r'C:\Users\huawei\Desktop\.ipynb_checkpoints\data.xlsx',index_col= 'id')
数据清理
- 将dataframe时间数据转化成datetime格式的数据类型
df['orderTime'] = pd.to_datetime(df.orderTime)
df['payTime'] = pd.to_datetime(df.payTime)
- 删除不合理数据
df['pay_gap'] = (df.payTime-df.orderTime).dt.total_seconds() ###换成秒数
df.drop(index = df[df.pay_gap > 1800].index,inplace = True) ##删除支付时间过长的
df.drop(index = df[df.pay_gap < 0].index,inplace = True) ###删除支付时间早于下单时间
df[df.orderAmount < 0]
df[df.payment < 0]
df.drop(index = df[df.payment < 0].index,inplace = True) #删除支付金额为负
df.drop(index = df[df.payment > df.orderAmount].index,inplace = True)
df.orderID.unique().size
df.orderID.duplicated()
df.drop(index = df[df.orderID.duplicated()].index,inplace = True) #删除orderID重复值
df.userID.unique().size
df.userID.duplicated()
df.goodsID.unique().size
df[df.goodsID == 'PR000000'].size
df.drop(index = df[df.goodsID == "PR000000"].index,inplace = True)
df[df.chanelID.isnull()]
df['chanelID'].fillna(value = df.chanelID.mode()[0],inplace = True)
df.platfromType.unique()
df['platfromType'] = df.platfromType.str.replace(" ","") #
###可能还会遇到大小写问题,需要转换使用upper()和loewr()函数
数据分析
1.基本销售情况
plt.rcParams['font.sans-serif']='SimHei' #设置中文字体显示
df['month'] = df['orderTime'].dt.month ##提取月份
plt.figure("销售情况",figsize = (10,8))
plt.grid(alpha = 0.5)
df_new = df.groupby('month')['orderAmount','payment','chargeback'].agg('sum')
x = df_new.index
y1,y2 = [df_new.orderAmount/10000,df_new.payment/10000]
y3 = df[df['chargeback'] == "否"].groupby('month')['payment'].sum().values/10000
plt.plot(x,y1,label = '总销售额',color = 'r',marker = '*')
plt.plot(x,y2,label = '成交额',color = 'g',marker = '_')
plt.plot(x,y3,label = '实际成交额',color = 'orange',marker = 'o')
x_ticks_label = ['{}月份'.format(i) for i in x]
plt.xticks(x,x_ticks_label)
plt.xlabel('月份')
plt.ylabel('销售额')
plt.title("销售情况分析",color = "r",size = 20)
##添加数据标签
for a,b,c,d in zip(x,y1,y2,y3):
plt.annotate('(%.2f)'%(b),xy=(a,b),xytext=(-10,10),textcoords='offset points')
plt.annotate('(%.2f)'%(c),xy=(a,c),xytext=(-10,10),textcoords='offset points')
plt.annotate('(%.2f)'%(d),xy=(a,d),xytext=(-10,10),textcoords='offset points')
plt.legend(prop = my_font,loc = 'upper left')
ax = plt.gca()
ax.spines['right'].set_color('none') ##去掉右边和上边的边框
ax.spines['top'].set_color('none')
plt.show()
2.销售渠道分析
df.chanelID.unique().size
plt.figure(figsize = (15,9))
cus = df.groupby('chanelID')['userID'].count()
label = cus.index
plt.pie(cus,labels = label,autopct='%1.1f%%',rotatelabels=True,shadow=True)
plt.title("各渠道用户占比",size = 20)
plt.show()
平台来源分析
df.platfromType.unique()
plat_cus = df.pivot_table(index = 'platfromType',
values = ['userID','orderAmount'],
aggfunc = {'userID':'count','orderAmount':'mean'})
data1 = plat_cus.userID
data2 = plat_cus.orderAmount
data3 = [1]
labels = plat_cus.index
def pie_fun(x,y,z):
fig,ax = plt.subplots()
ax.pie(x,radius = 1,autopct = '%1.1f%%',pctdistance=0.75)
ax.pie(y,radius = 0.6,colors = 'white')
ax.set(aspect = "equal",title = "不同平台的{}占比环形图".format(x.name))
plt.legend(z,bbox_to_anchor = (1,1),loc = 'best')
plt.show()
3.客户分析
订单分析
df['weekday'] = df.orderTime.dt.dayofweek
df.weekday.unique()
df_w = df.groupby('weekday')['orderID'].count()
df_w
plt.figure('figure3')
df_wX = ['周一','周二','周三','周四','周五','周六','周日']
df_wY = df_w.values
df_bar= plt.bar(df_wX,height = df_wY,color=['r','g','b','r','g','b'],width = 0.3)
for b in df_bar:
height = b.get_height()
plt.text(b.get_x()+b.get_width()/2,height+0.6,str(height),ha = 'center')
plt.show()
RFM模型
df1 = df.copy()
df1.drop(index = df1[df1['chargeback'] == '是'].index,inplace = True)
df1['orderTime'] = pd.to_datetime(df1.orderTime,format = '%Y-%m-%d')
df1.set_index('userid',drop = True,inplace = True)
df1['orders'] = 1
RFMdf = df1.pivot_table(index = ['userid'],
values = ['orderAmount','orderTime','orders'],
aggfunc = {'orderAmount':'sum',
'orderTime':'max',
'orders':'sum'})
RFMdf['R'] = (RFMdf.orderTime.max()-RFMdf.orderTime).dt.days
RFMdf.rename(columns = {"orderAmount":'M',"orders":'F'},inplace = True)
RFMdf[['R','F','M']].apply(lambda x: x-x.mean())
def rfm_fun(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
RFMdf['label'] = RFMdf[['R','F','M']].apply(lambda x: x-x.mean()).apply(rfm_fun,axis = 1)
# tabel = RFMdf.groupby('label').count()
plt.figure('figure4',figsize = (10,8))
RFMdf.label.value_counts().plot.bar()
plt.xticks(rotation = 0)
分析报告撰写
一、研究背景
互联网时代,竞争压力大,对客户的行为及销售情况做到清晰把握,才能实现最大盈利。
二、分析思路
分析的目的是了解电商的销售情况及用户行为,基于销售中存在的问题及根据客户类型,提出建议。
三、分析结果
(1)基本销售情况
该平台2019年拥有客户数77370,销售总额为10622.787947万元,而实际成交额远低于销售总额,为8708.58。因为退回率比较高,为13.18%。具体的销售情况如下:在6,7,8,9,这几个月的退款较多,实际成交额与销售总额差距较大。
(2)销售渠道分析
该平台销售渠道较多,包括15个,其中客户数最多的是渠道-0896,占16.1%。而从客户下单的渠道来看,客户用的最多的是APP和微信APP。但是订单数最多的是WechatMP和WechatShop,分别占比20.2%,18.45%。
(3)订单分析
下面是周内的下单情况,可见在周末和周一周二客户下单量较高,而在中间几天下单量较低,可能因为 周内工作学习较忙。
(4)客户复购率
从整体的复购率来看,比率比较低,最高的仅有3%。后半年的复购率比前半年较高 。
(5)客户类型分析
从RFM模型分析,该平台的主要客户留存不高,醉主要的重要价值客户和重要保持客户较少,而一般发展客户和一般挽留客户较高。
四、结论建议
该平台存在很大问题,主要要从客户的偏好和满意度出发,增加黏性。