以下是本人做的 电商打折套路分析第二部分 分析代码以及结论
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings
from bokeh.plotting import figure ,show,output_file
from bokeh.models import ColumnDataSource
from bokeh.models import HoverTool
import os
os.chdir("C:\\Users\\Administrator\\Desktop\\python项目\\2电商打折")
df=pd.read_excel("双十一数据.xlsx",sheetname=0)
df.fillna(0,inplace=True)
df.index=df["update-time"]
df["date"]=df.index.day
data_zk=result3_data2[result3_data2["zkl"]<0.96]
result4_zkld=data_zk.groupby("店名_x")["zkl"].mean()
n_dz=data_zk["店名_x"].value_counts()
n_bdz=result3_data2["店名_x"].value_counts()
result4_dzspbl=pd.DataFrame({"打折商品数":n_dz,"不打折商品数":n_bdz})
result4_dzspbl["打折商品比例"]=result4_dzspbl["打折商品数"]/(result4_dzspbl["不打折商品数"]+result4_dzspbl["打折商品数"])
result4_sum=result2_data.copy()
result4_data=pd.merge(pd.DataFrame(result4_zkld),result4_dzspbl,left_index=True,right_index=True,how="inner")
result4_data=pd.merge(result4_data,result4_sum,left_index=True,right_index=True,how="inner")
from bokeh.models.annotations import Span,Label,BoxAnnotation
bokeh_data=result4_data[["zkl","sum","打折商品比例"]]
bokeh_data.columns=["zkl","amount","pre"]
bokeh_data["size"]=bokeh_data["amount"]*0.5
source=ColumnDataSource(bokeh_data)
x_mean=bokeh_data["pre"].mean()
y_mean=bokeh_data["zkl"].mean()
hover=HoverTool(#因为小的和大的合并以后才能图是显示所有字段
tooltips=[
("品牌","@index"),
("折扣率","@zkl"),
("打折的商品数量","@size"),
("打折的商品比例","@pre")
])
p=figure(plot_width=600,plot_height=600,title="各个商品打折套路解析",
x_axis_label="参与打折商品比例", y_axis_label="折扣率",
tools=[hover,"box_select,pan,reset,wheel_zoom,crosshair"]
)
p.circle_x(x="pre",y="zkl",source=source,size="size",fill_color="red",
line_color="green",fill_alpha=0.8,line_dash=[6,3]
)#散点图
p.ygrid.grid_line_dash=[3,4]
p.xgrid.grid_line_dash=[3,4]
output_file("project04.html")
x=Span(location=x_mean,dimension="height",line_color="green",line_dash=[6,4],line_alpha=1)
y=Span(location=y_mean,dimension="width",line_color="green",line_dash=[6,4],line_alpha=1)
p.add_layout(x)
p.add_layout(y)
bg1=BoxAnnotation(bottom=x_mean,right=y_mean,fill_alpha=0.1,fill_color="olive")
label1=Label(x=0.15,y=0.55,text="少量大打折")
p.add_layout(bg1)
p.add_layout(label1)
bg2=BoxAnnotation(bottom=x_mean,right=y_mean,fill_alpha=0.1,fill_color="firebrick")
label2=Label(x=0.3,y=0.4,text="大量大打折")
p.add_layout(bg2)#bottom=x_mean,right=y_mean x均数的下面,y均数的右面
p.add_layout(label2)
bg3=BoxAnnotation(top=x_mean,right=y_mean,fill_alpha=0.1,fill_color="firebrick")
label3=Label(x=0.15,y=0.4,text="少量大打折")
p.add_layout(bg3)
p.add_layout(label3)
bg4=BoxAnnotation(top=x_mean,right=y_mean,fill_alpha=0.1,fill_color="olive")
label4=Label(x=0.25,y=0.55,text="大量少打折")
p.add_layout(bg4)
p.add_layout(label4)
show(p)
结论:从数量上来说,少量大打折是多数的,占了4份,而大量大打折是少数的,所以双十一大部分商品其实没有打折,少部分商品才参与打折。