Travel Tips
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Python数据分析实战——电商打折套路解析三
要求:
① 解析出不同品牌的参与打折商品比例及折扣力度,并做散点图,总结打折套路
* 用bokeh绘制散点图,x轴为参与打折商品比例,y轴为折扣力度,点的大小代表该品牌参加双11活动的商品总数
提示:
① 折扣力度为该品牌所有打折商品的折扣均值,这里去掉品牌中不打折的数据
② 绘制散点图后,可以将x、y轴绘制均值辅助线,将绘图空间分为四个象限,基于该象限来总结套路
data_zk = result3_data2[result3_data2['zkl']<0.95] # 删除未打折数据 result4_zkld = data_zk.groupby('店名_y')['zkl'].mean() # 筛选出不同品牌的折扣率 n_dz = data_zk['店名_y'].value_counts() n_zs = result3_data2['店名_y'].value_counts() result4_dzspbl = pd.DataFrame({'打折商品数':n_dz,'商品总数':n_zs}) result4_dzspbl['参与打折商品比例'] = result4_dzspbl['打折商品数'] / result4_dzspbl['商品总数'] result4_dzspbl.dropna(inplace = True) #print(result4_dzspbl.head()) # 计算出不同品牌参与打折商品比例 result4_sum = result2_data.copy() # 筛选出品牌参加双11活动的商品总数 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') # 合并数据 result3_data2
from bokeh.models.annotations import Span # 导入Span模块 from bokeh.models.annotations import Label # 导入Label模块 from bokeh.models.annotations import BoxAnnotation # 导入BoxAnnotation模块 bokeh_data = result4_data[['zkl','sum','参与打折商品比例']] bokeh_data.columns = ['zkl','amount','pre'] bokeh_data['size'] = bokeh_data['amount'] * 0.03 source = ColumnDataSource(bokeh_data) # 创建ColumnDataSource数据 x_mean = bokeh_data['pre'].mean() y_mean = bokeh_data['zkl'].mean() hover = HoverTool(tooltips=[("品牌", "@index"), ("折扣率", "@zkl"), ("商品总数", "@amount"), ("参与打折商品比例", "@pre"), ]) # 设置标签显示内容 p = figure(plot_width=600, plot_height=600, title="各个品牌打折套路解析" , tools=[hover,'box_select,reset,wheel_zoom,pan,crosshair']) # 构建绘图空间 p.circle_x(x = 'pre',y = 'zkl',source = source,size = 'size', fill_color = 'red',line_color = 'black',fill_alpha = 0.6,line_dash = [8,3]) p.ygrid.grid_line_dash = [6, 4] p.xgrid.grid_line_dash = [6, 4] # 散点图 x = Span(location=x_mean, dimension='height', line_color='green',line_alpha = 0.7, line_width=1.5, line_dash = [6,4]) y = Span(location=y_mean, dimension='width', line_color='green',line_alpha = 0.7, line_width=1.5, line_dash = [6,4]) p.add_layout(x) p.add_layout(y) # 绘制辅助线 bg1 = BoxAnnotation(bottom=y_mean, right=x_mean,fill_alpha=0.1, fill_color='olive') label1 = Label(x=0.1, y=0.55,text="少量大打折",text_font_size="10pt" ) p.add_layout(bg1) p.add_layout(label1) # 绘制第一象限 bg2 = BoxAnnotation(bottom=y_mean, left=x_mean,fill_alpha=0.1, fill_color='firebrick') label2 = Label(x=0.7, y=0.55,text="大量大打折",text_font_size="10pt" ) p.add_layout(bg2) p.add_layout(label2) # 绘制第二象限 bg3 = BoxAnnotation(top=y_mean, right=x_mean,fill_alpha=0.1, fill_color='firebrick') label3 = Label(x=0.1, y=0.80,text="少量少打折",text_font_size="10pt" ) p.add_layout(bg3) p.add_layout(label3) # 绘制第三象限 bg4 = BoxAnnotation(top=y_mean, left=x_mean,fill_alpha=0.1, fill_color='olive') label4 = Label(x=0.7, y=0.80,text="少量大打折",text_font_size="10pt" ) p.add_layout(bg4) p.add_layout(label4) # 绘制第四象限 show(p)
''' 结论: 少量少打折:包括雅诗兰黛、娇兰、兰蔻、薇姿、玉兰油等共5个品牌。 少量大打折:包括悦诗风吟、兰芝、欧珀莱等3个品牌。该类品牌的打折商品较少,但折扣力度较大。 大量小打折:包括妮维雅、美宝莲、蜜丝佛陀等3个品牌。该类型有半数以上的商品都参与了打折活动,但折扣力度并不大。 大量大打折:包括相宜本草、佰草集、自然堂等三大国产品牌。这些品牌不仅有90%以上的商品参与了折扣活动,而且折扣力度很大。 '''
资料链接;链接: https://pan.baidu.com/s/1IKJJJ9laXvGbgyp_Gq4v0A 密码: 2r11
Sed ac lorem felis. Ut in odio lorem. Quisque magna dui, maximus ut commodo sed, vestibulum ac nibh. Aenean a tortor in sem tempus auctor
December 4, 2020 at 3:12 pm
Sed ac lorem felis. Ut in odio lorem. Quisque magna dui, maximus ut commodo sed, vestibulum ac nibh. Aenean a tortor in sem tempus auctor
December 4, 2020 at 3:12 pm
Donec in ullamcorper quam. Aenean vel nibh eu magna gravida fermentum. Praesent eget nisi pulvinar, sollicitudin eros vitae, tristique odio.
December 4, 2020 at 3:12 pm
我是 s enim interduante quis metus. Duis porta ornare nulla ut bibendum
Rosie
6 minutes ago