(Adventure项目)自行车业务数据分析报告(五)
项目背景
- Adventure Works Cycles是Adventure Works样本数据库所虚构的公司,这是一家大型跨国制造公司。该公司生产和销售自行车到北美,欧洲和亚洲的商业市场。虽然其基地业务位于华盛顿州博塞尔,拥有290名员工,但几个区域销售团队遍布整个市场。
2019年11月自行车业务分析报告
目录:
- 一、自行车整体销售表现
- 二、2019年11月自行车地域销售表现
- 三、2019年11月自行车产品销售表现
- 四、用户行为分析
- 五、2019年11月热品销售分析
本文主要介绍第五部分:2019年11月热品销售分析,其他章节可访问本专栏Adventure自行车项目,建议订阅收藏
五、2019年11月热品销售分析
#gather_customer_order在分析自行车整体表现得时已从数据库导入表( dw_customer_order),并筛选仅自行车数据,这里不再导入
gather_customer_order.head()
create_date | product_name | cpzl_zw | cplb_zw | order_num | customer_num | sum_amount | is_current_year | is_last_year | is_yesterday | is_today | is_current_month | is_current_quarter | chinese_province | chinese_city | chinese_territory | create_year_month | |
152 | 2019-01-02 | Mountain-100 Silver | 山地自行车 | 自行车 | 1 | 1 | 3399.990000 | 0 | 0 | 0 | 0 | 0 | 0 | 江苏省 | 盐城市 | 华东 | 2019-01 |
153 | 2019-01-02 | Mountain-200 Black | 山地自行车 | 自行车 | 1 | 1 | 2294.990000 | 0 | 0 | 0 | 0 | 0 | 0 | 海南省 | 焦作市 | 华南 | 2019-01 |
154 | 2019-01-02 | Mountain-200 Black | 山地自行车 | 自行车 | 1 | 1 | 2294.990000 | 0 | 0 | 0 | 0 | 0 | 0 | 陕西省 | 阜阳市 | 西北 | 2019-01 |
155 | 2019-01-02 | Mountain-200 Black | 山地自行车 | 自行车 | 1 | 1 | 2294.990000 | 0 | 0 | 0 | 0 | 0 | 0 | 贵州省 | 贵阳市 | 西南 | 2019-01 |
156 | 2019-01-02 | Mountain-200 Black | 山地自行车 | 自行车 | 1 | 1 | 2049.098200 | 0 | 0 | 0 | 0 | 0 | 0 | 贵州省 | 铜仁市 | 西南 | 2019-01 |
5.1 11月产品销量TOP10产品,销售数量及环比
- 我们在分析“2019年11月自行车产品销售表现”时已计算出11月所有产品的销量及环比,这里不在重复计算,直接使用gather_customer_order_month_10_11、gather_customer_order_month_11
#筛选11月数据
gather_customer_order_11 = gather_customer_order.loc[gather_customer_order['create_year_month'] == '2019-11']
计算TOP10产品
#计算产品销售数量,\ 为换行符
#按照销量降序,取TOP10产品
customer_order_11_top10 = gather_customer_order_11.groupby(by = 'product_name').order_num.count().reset_index().\
sort_values(by = 'order_num',ascending = False).head(10)
customer_order_11_top10
product_name | order_num | |
2 | Mountain-200 Black | 416 |
3 | Mountain-200 Silver | 390 |
7 | Road-150 Red | 380 |
14 | Road-750 Black | 292 |
11 | Road-550-W Yellow | 276 |
8 | Road-250 Black | 256 |
10 | Road-350-W Yellow | 198 |
9 | Road-250 Red | 158 |
15 | Touring-1000 Blue | 154 |
16 | Touring-1000 Yellow | 139 |
计算TOP10销量及环比
list(customer_order_11_top10['product_name'])
['Mountain-200 Black',
'Mountain-200 Silver',
'Road-150 Red',
'Road-750 Black',
'Road-550-W Yellow',
'Road-250 Black',
'Road-350-W Yellow',
'Road-250 Red',
'Touring-1000 Blue',
'Touring-1000 Yellow']
#查看11月环比数据
gather_customer_order_month_10_11.head()
create_year_month | product_name | order_month_product | cpzl_zw | sum_order_month | order_num_proportio | order_num_diff | |
63 | 2019-10 | Mountain-100 Black | 42 | 山地自行车 | 1028 | 0.040856 | 0.000000 |
70 | 2019-11 | Mountain-100 Black | 50 | 山地自行车 | 1088 | 0.045956 | 0.190476 |
64 | 2019-10 | Mountain-100 Silver | 31 | 山地自行车 | 1028 | 0.030156 | 0.000000 |
71 | 2019-11 | Mountain-100 Silver | 36 | 山地自行车 | 1088 | 0.033088 | 0.161290 |
65 | 2019-10 | Mountain-200 Black | 379 | 山地自行车 | 1028 | 0.368677 | 0.000000 |
- 这里我们只需要五个字段:create_year_month月份,product_name产品名,order_month_product本月销量,cpzl_zw产品类别,
order_num_diff本月产品销量环比
customer_order_month_10_11 = gather_customer_order_month_10_11[['create_year_month','product_name','order_month_product','cpzl_zw','order_num_diff']]
customer_order_month_10_11 = customer_order_month_10_11[customer_order_month_10_11['product_name'].\
isin(list(customer_order_11_top10['product_name']))]
customer_order_month_10_11['category'] = '本月TOP10销量'
customer_order_month_10_11.head()
create_year_month | product_name | order_month_product | cpzl_zw | order_num_diff | category | |
65 | 2019-10 | Mountain-200 Black | 378 | 山地自行车 | 0.000000 | 本月TOP10销量 |
72 | 2019-11 | Mountain-200 Black | 434 | 山地自行车 | -0.000871 | 本月TOP10销量 |
66 | 2019-10 | Mountain-200 Silver | 351 | 山地自行车 | 0.000000 | 本月TOP10销量 |
73 | 2019-11 | Mountain-200 Silver | 400 | 山地自行车 | -0.008309 | 本月TOP10销量 |
72 | 2019-10 | Road-150 Red | 313 | 公路自行车 | 0.000000 | 本月TOP10销量 |
5.2 11月增速TOP10产品,销售数量及环比
customer_order_month_11 = gather_customer_order_month_10_11.loc[gather_customer_order_month_10_11['create_year_month'] == '2019-11'].\
sort_values(by = 'order_num_diff',ascending = False).head(10)
customer_order_month_11
create_year_month | product_name | order_month_product | cpzl_zw | sum_order_month | order_num_proportio | order_num_diff | |
70 | 2019-11 | Mountain-100 Black | 51 | 山地自行车 | 1148 | 0.044425 | 0.344869 |
52 | 2019-11 | Touring-2000 Blue | 93 | 旅游自行车 | 503 | 0.184891 | 0.181567 |
75 | 2019-11 | Mountain-500 Black | 57 | 山地自行车 | 1148 | 0.049652 | 0.153533 |
50 | 2019-11 | Touring-1000 Blue | 157 | 旅游自行车 | 503 | 0.312127 | 0.139822 |
80 | 2019-11 | Road-150 Red | 391 | 公路自行车 | 1787 | 0.218802 | 0.121275 |
83 | 2019-11 | Road-350-W Yellow | 201 | 公路自行车 | 1787 | 0.112479 | 0.086845 |
81 | 2019-11 | Road-250 Black | 262 | 公路自行车 | 1787 | 0.146614 | 0.078759 |
85 | 2019-11 | Road-650 Black | 104 | 公路自行车 | 1787 | 0.058198 | 0.060793 |
51 | 2019-11 | Touring-1000 Yellow | 142 | 旅游自行车 | 503 | 0.282306 | 0.040209 |
82 | 2019-11 | Road-250 Red | 160 | 公路自行车 | 1787 | 0.089536 | 0.011373 |
customer_order_month_11_top10_seep = gather_customer_order_month_10_11.loc[gather_customer_order_month_10_11['product_name'].\
isin(list(customer_order_month_11['product_name']))]
筛选我们需要的四个字段:create_year_month月份,product_name产品名,order_month_product本月销量,cpzl_zw产品类别,
order_num_diff本月产品销量环比
customer_order_month_11_top10_seep = customer_order_month_11_top10_seep[['create_year_month','product_name','order_month_product','cpzl_zw','order_num_diff']]
customer_order_month_11_top10_seep['category'] = '本月TOP10增速'
customer_order_month_11_top10_seep.head()
create_year_month | product_name | order_month_product | cpzl_zw | order_num_diff | category | |
63 | 2019-10 | Mountain-100 Black | 33 | 山地自行车 | 0.000000 | 本月TOP10增速 |
70 | 2019-11 | Mountain-100 Black | 51 | 山地自行车 | 0.344869 | 本月TOP10增速 |
68 | 2019-10 | Mountain-500 Black | 43 | 山地自行车 | 0.000000 | 本月TOP10增速 |
75 | 2019-11 | Mountain-500 Black | 57 | 山地自行车 | 0.153533 | 本月TOP10增速 |
72 | 2019-10 | Road-150 Red | 313 | 公路自行车 | 0.000000 | 本月TOP10增速 |
合并TOP10销量表customer_order_month_10_11,TOP10增速customer_order_month_11_top10_seep
#axis = 0按照行维度合并,axis = 1按照列维度合并
hot_products_11 = pd.concat([customer_order_month_10_11,customer_order_month_11_top10_seep],axis = 0)
hot_products_11.tail()
create_year_month | product_name | order_month_product | cpzl_zw | order_num_diff | category | |
50 | 2019-11 | Touring-1000 Blue | 157 | 旅游自行车 | 0.139822 | 本月TOP10增速 |
46 | 2019-10 | Touring-1000 Yellow | 111 | 旅游自行车 | 0.000000 | 本月TOP10增速 |
51 | 2019-11 | Touring-1000 Yellow | 142 | 旅游自行车 | 0.040209 | 本月TOP10增速 |
47 | 2019-10 | Touring-2000 Blue | 64 | 旅游自行车 | 0.000000 | 本月TOP10增速 |
52 | 2019-11 | Touring-2000 Blue | 93 | 旅游自行车 | 0.181567 | 本月TOP10增速 |
字段注释:
create_year_month:月份,product_name:产品名,order_month_product:本月产品销量,order_num_diff:本月产品环比,category:分类
#存入数据库
engine = sqlalchemy.create_engine('mysql://id:********@xxx.xx.xxx.xxx:3306/db?charset=gbk')
hot_products_11.to_sql('hot_products_november_leosong',con = engine,if_exists='append', index=False)