(Adventure项目)自行车业务数据分析报告(二)

(Adventure项目)自行车业务数据分析报告(二)

项目背景
  • Adventure Works Cycles是Adventure Works样本数据库所虚构的公司,这是一家大型跨国制造公司。该公司生产和销售自行车到北美,欧洲和亚洲的商业市场。虽然其基地业务位于华盛顿州博塞尔,拥有290名员工,但几个区域销售团队遍布整个市场。

2019年11月自行车业务分析报告

目录:

  • 一、自行车整体销售表现
  • 二、2019年11月自行车地域销售表现
  • 三、2019年11月自行车产品销售表现
  • 四、用户行为分析
  • 五、2019年11月热品销售分析

本文主要介绍第二部分:2019年11月自行车地域销售表现,其他章节可访问本专栏Adventure自行车项目,建议订阅收藏

二、2019年11月自行车地域销售表现

2.1、源数据dw_customer_order,数据清洗筛选10月11月数据

#gather_customer_order在分析自行车整体表现时已从数据库导入表(dw_customer_order),并筛选仅自行车数据,这里不再导入
gather_customer_order.head()
create_dateproduct_namecpzl_zwcplb_zworder_numcustomer_numsum_amountis_current_yearis_last_yearis_yesterdayis_todayis_current_monthis_current_quarterchinese_provincechinese_citychinese_territorycreate_year_month
1522019-01-02Mountain-100 Silver山地自行车自行车113399.990000000000江苏省盐城市华东2019-01
1532019-01-02Mountain-200 Black山地自行车自行车112294.990000000000海南省焦作市华南2019-01
1542019-01-02Mountain-200 Black山地自行车自行车112294.990000000000陕西省阜阳市西北2019-01
1552019-01-02Mountain-200 Black山地自行车自行车112294.990000000000贵州省贵阳市西南2019-01
1562019-01-02Mountain-200 Black山地自行车自行车112049.098200000000贵州省铜仁市西南2019-01

2.1.1 筛选10、11月的自行车数据,赋值变量为gather_customer_order_10_11

#筛选10月11月自行车数据
gather_customer_order_10_11 = gather_customer_order[gather_customer_order['create_year_month'].isin(['2019-10','2019-11'])]

2.1.1 查看10月、11月的自行车订单数量

#10月11月自行车订单数据共6335条
len(gather_customer_order_10_11)
6335

2.2、2019年11月自行车区域销售量表现

2.2.1 请按照’chinese_territory’,‘create_year_month’,区域、月份分组,订单量求和、销售金额求和,赋予变量gather_customer_order_10_11_group,记得重置索引

#按照区域、月分组,订单量求和,销售金额求和
gather_customer_order_10_11_group= gather_customer_order_10_11.groupby(['chinese_territory','create_year_month'])\
.agg({'order_num':sum,'sum_amount':sum}).reset_index()
gather_customer_order_10_11_group.head()
chinese_territorycreate_year_monthorder_numsum_amount
0东北2019-10239433802.146000
1东北2019-11255476112.870700
2华东2019-107871443753.658800
3华东2019-118711651823.701100
4华中2019-10470868236.766500

2.2.2 求不同区域10月11月的环比

步骤

  • 1、获得去重区域的列表region_list
  • 2、利用for循环区域列表,结合loc定位符合区域
  • 3、利用pct_change()函数实现环比效果
  • 4、形成新的Series
  • 5、利用Series带的索引,合并到gather_customer_order_10_11_group中
#将区域存为列表
region_list=list(gather_customer_order_10_11_group['chinese_territory'].unique())
region_list
['东北', '华东', '华中', '华北', '华南', '台港澳', '西北', '西南']
#pct_change()当前元素与先前元素的相差百分比,求不同区域10月11月环比
order_x = pd.Series([])
amount_x = pd.Series([])
for i in region_list:
    a=gather_customer_order_10_11_group.loc[gather_customer_order_10_11_group['chinese_territory']==i]['order_num'].pct_change().fillna(0)
    b=gather_customer_order_10_11_group.loc[gather_customer_order_10_11_group['chinese_territory']==i]['sum_amount'].pct_change().fillna(0)
    order_x=order_x.append(a)
    amount_x = amount_x.append(b)
gather_customer_order_10_11_group['order_diff']=order_x
gather_customer_order_10_11_group['amount_diff']=amount_x
#10月11月各个区域自行车销售数量、销售金额环比
gather_customer_order_10_11_group.head()
chinese_territorycreate_year_monthorder_numsum_amountorder_diffamount_diff
0东北2019-10239433802.1460000.0000000.000000
1东北2019-11255476112.8707000.0669460.097535
2华东2019-107871443753.6588000.0000000.000000
3华东2019-118711651823.7011000.1067340.144117
4华中2019-10470868236.7665000.0000000.000000

字段注释:

chinese_territory:区域,create_year_month:时间,order_num:区域销售数量,sum_amount:区域销售金额,order_diff:本月销售数量环比,

amount_diff:本月销售金额环比

2.2.3 将最终的gather_customer_order_10_11_group的DataFrame存入Mysql的pt_bicy_november_territory_2当中,请使用追加存储。

#将数据存入数据库
engine = sqlalchemy.create_engine('mysql://ID:********@xxx.xx.xx.xxx:3306/db?charset=gbk')
gather_customer_order_10_11_group.to_sql('name',con=engine,if_exists='append',index=False)

2.3、2019年11月自行车销售量TOP10城市环比

2.3.1 筛选11月自行车交易数据 赋予变量为gather_customer_order_11

#筛选11月自行车交易数据
gather_customer_order_11 = gather_customer_order_10_11[gather_customer_order_10_11['create_year_month']=='2019-11']

2.3.2 将gather_customer_order_11按照chinese_city城市分组,求和销售数量order_num,最终查看11月自行车销售数量前十城市,赋予变量gather_customer_order_city_head

gather_customer_order_city_11= gather_customer_order_11.groupby('chinese_city')\
['order_num'].sum().reset_index()
#11月自行车销售数量前十城市
gather_customer_order_city_head = gather_customer_order_city_11.sort_values('order_num',ascending=False).head(10)
#查看11月自行车销售数量前十城市
gather_customer_order_city_head
chinese_cityorder_num
31北京市80
82广州市49
144深圳市45
3上海市45
207郑州市44
59天津市43
210重庆市41
121武汉市40
219长沙市37
189西安市36

2.3.3 根据gather_customer_order_city_head的前十城市,查看10月11月自行车销售数据gather_customer_order_10_11,赋予变量gather_customer_order_10_11_head

#筛选销售前十城市,10月11月自行车销售数据
gather_customer_order_10_11_head = gather_customer_order_10_11[gather_customer_order_10_11['chinese_city'].\
isin (list(gather_customer_order_city_head['chinese_city']))]
gather_customer_order_10_11_head.head()
create_dateproduct_namecpzl_zwcplb_zworder_numcustomer_numsum_amountis_current_yearis_last_yearis_yesterdayis_todayis_current_monthis_current_quarterchinese_provincechinese_citychinese_territorycreate_year_month
1045812019-10-01Mountain-100 Black山地自行车自行车113374.990000000000直辖市重庆市西南2019-10
1045852019-10-01Mountain-200 Black山地自行车自行车112049.098200000000直辖市上海市华东2019-10
1046062019-10-01Mountain-400-W Silver山地自行车自行车221538.980000000000广东省广州市华南2019-10
1046672019-10-01Road-150 Red公路自行车自行车113578.270000000000湖南省长沙市华中2019-10
1046912019-10-01Road-550-W Yellow公路自行车自行车111120.490000000000河北省深圳市华南2019-10

2.3.4 根据gather_customer_order_10_11_head,分组计算前十城市,自行车销售数量销售金额,赋予变量gather_customer_order_city_10_11
[

#分组计算前十城市,自行车销售数量销售金额
gather_customer_order_city_10_11 = gather_customer_order_10_11_head.groupby(['chinese_city','create_year_month']).\
agg({'order_num':sum,'sum_amount':sum}).reset_index()
gather_customer_order_city_10_11.head()
chinese_citycreate_year_monthorder_numsum_amount
0上海市2019-103975255.468500
1上海市2019-114583769.892400
2北京市2019-1053101729.543300
3北京市2019-1180154997.506200
4天津市2019-102955328.630600

2.3.5 根据gather_customer_order_city_10_11,计算前10的销售金额及销售量环比,方法参照2.2.2

#计算前十城市环比
city_top_list = list(gather_customer_order_city_head['chinese_city'])
order_top_x = pd.Series([])
amount_top_x = pd.Series([])
for i in city_top_list:
    #print(i)
    a=gather_customer_order_city_10_11.loc[gather_customer_order_city_10_11['chinese_city']==i]['order_num'].pct_change().fillna(0)
    b=gather_customer_order_city_10_11.loc[gather_customer_order_city_10_11['chinese_city']==i]['sum_amount'].pct_change().fillna(0)
    order_top_x=order_top_x.append(a)
    amount_top_x =amount_top_x.append(b)
#order_diff销售数量环比,amount_diff销售金额环比
gather_customer_order_city_10_11['order_diff']=order_top_x
gather_customer_order_city_10_11['amount_diff']=amount_top_x
gather_customer_order_city_10_11.head(6)
chinese_citycreate_year_monthorder_numsum_amountorder_diffamount_diff
0上海市2019-103975255.4685000.0000000.000000
1上海市2019-114583769.8924000.1538460.113140
2北京市2019-1053101729.5433000.0000000.000000
3北京市2019-1180154997.5062000.5094340.523623
4天津市2019-102955328.6306000.0000000.000000
5天津市2019-114385048.3810000.4827590.537150

字段注释

chinese_city:城市,create_year_month:时间,order_num:本月销售数量,sum_amount:本月销售金额,order_diff:本月销售数量环比,

amount_diff:本月销售金额环比

2.3.6 将最终的gather_customer_order_city_10_11的DataFrame存入Mysql的pt_bicy_november_october_city_3当中,请使用追加存储。

#存入数据库
engine = sqlalchemy.create_engine('mysql://id:*******@xxx.xx.xxx.xx:3306/dab?charset=gbk')
gather_customer_order_city_10_11.to_sql('name',con=engine,if_exists='append',index=False)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值