美文网首页
自行车业务分析 3.3

自行车业务分析 3.3

作者: 人间桑 | 来源:发表于2020-06-10 16:41 被阅读0次

3.3、公路/山地/旅游自行车细分市场表现

#查看自行车有那些产品子类

gather_customer_order['cpzl_zw'].unique()

gather_customer_order['cpzl_zw'].drop_duplicates(keep='first')

公路自行车细分市场销量表现

gather_customer_order_road = gather_customer_order[gather_customer_order['cpzl_zw'] == '公路自行车']

作业 3.3.2、求公路自行车不同型号'product_name'字段的产品销售数量,赋值变量为gather_customer_order_road_month

#求公路自行车不同型号产品销售数量

gather_customer_order_road_month = gather_customer_order_road.groupby(by = ['create_year_month','product_name']).agg({'order_num':'sum'}).reset_index()

gather_customer_order_road_month['cpzl_zw'] = '公路自行车'

#每个月公路自行车累计销售数量

gather_customer_order_road_month_sum = gather_customer_order_road.groupby('create_year_month').agg({'order_num':'sum'}).reset_index()

作业 3.3.3、在gather_customer_order_road_month基础上,合并公路自行车每月累计销售数量gather_customer_order_road_month_sum,主键为'create_year_month'

gather_customer_order_road_month = pd.merge(gather_customer_order_road_month,gather_customer_order_road_month_sum,on='create_year_month',how='left')

gather_customer_order_road_month['order_num_prop']=gather_customer_order_road_month['order_num_x']/gather_customer_order_road_month['order_num_y']

gather_customer_order_road_month

山地、公路和旅游自行车全部进行以上操作

#将山地自行车、旅游自行车、公路自行车每月销量信息合并

gather_customer_order_month = pd.concat([gather_customer_order_road_month,gather_customer_order_Mountain_month,gather_customer_order_tour_month])

作业 3.3.5、新增一列'order_num_proportio',为销售量占每月自行车总销售量比率

#各类自行车,销售量占每月自行车总销售量比率

gather_customer_order_month['order_num_proportio'] = gather_customer_order_month.order_num_x/gather_customer_order_month.order_num_y

#order_month_product当月产品累计销量

#sum_order_month当月自行车总销量

gather_customer_order_month.rename(columns={'order_num_x':'order_month_product','order_num_y':'sum_order_month'})

gather_customer_order_month

计算2019年11月自行车环比

#计算11月环比,先筛选10月11月数据

gather_customer_order_month_10_11 = gather_customer_order_month[gather_customer_order_month.create_year_month.isin(['2019-10','2019-11'])]

#排序。将10月11月自行车销售信息排序

gather_customer_order_month_10_11 = gather_customer_order_month_10_11.sort_values(by = ['product_name','create_year_month'])

gather_customer_order_month_10_11.head(3)

product_name = list(gather_customer_order_month_10_11.product_name.drop_duplicates())

product_name

作业 3.3.8、计算自行车销售数量环比

#计算自行车销售数量环比

order_top_x = list([])

for i in product_name:

a=gather_customer_order_month_10_11[gather_customer_order_month_10_11['product_name']==i]['order_num_proportio'].pct_change().fillna(0)

order_top_x.extend(a)

gather_customer_order_month_10_11['order_num_diff'] = order_top_x

#筛选出11月自行车数据

gather_customer_order_month_11 = gather_customer_order_month_10_11[gather_customer_order_month_10_11['create_year_month'] == '2019-11']

gather_customer_order_month_11.head(3)

计算2019年1月至11月产品累计销量

作业 3.3.8、筛选2019年1月至11月自行车数据,赋予变量为gather_customer_order_month_1_11

gather_customer_order_month_1_11 = gather_customer_order_month[(gather_customer_order_month['create_year_month'].apply(lambda x:x[:4])=='2019') & (gather_customer_order_month['create_year_month']!='2019-12')]

#计算2019年1月至11月自行车累计销量

gather_customer_order_month_1_11_sum = gather_customer_order_month_1_11.groupby(by = 'product_name').order_month_product.sum().reset_index()

#重命名sum_order_1_11:1-11月产品累计销量

gather_customer_order_month_1_11_sum = gather_customer_order_month_1_11_sum.rename(columns = {'order_month_product':'sum_order_1_11'})

gather_customer_order_month_1_11_sum.head()

2019年11月自行车产品销量、环比、累计销量

#按相同字段product_name产品名,合并两张表

gather_customer_order_month_11 = pd.merge(gather_customer_order_month_11,gather_customer_order_month_1_11_sum,on='product_name',how='left')

gather_customer_order_month_11.head()

相关文章

  • 自行车业务分析 3.3

    3.3、公路/山地/旅游自行车细分市场表现 #查看自行车有那些产品子类 gather_customer_order...

  • 自行车业务分析 3.3 总结

    其实python处理数据的流程跟mysql非常相似,筛选-分组-聚类-连接 业务方面主要体现了分类的思想,按产品类...

  • Dashboard可视化看板

    项目背景:本文是基于上篇文章的延伸Adventure Works数据库自行车业务分析 为满足业务自主分析的需求,考...

  • 自行车业务分析 2.1

    二、2019年11月自行车地域销售表现 2.1、源数据dw_customer_order,数据清洗筛选10月11月...

  • 自行车业务分析 2.2

    2.2、2019年11月自行车区域销售量表现 作业 2.2.1 请按照'chinese_territory','c...

  • 自行车业务分析 复习

    总共载入三个表: gather_customer_order:创建日期,产品名,产品种类,订单数,客户数,总金额,...

  • 自行车业务分析 2.3

    2.3、2019年11月自行车销售量TOP10城市环比 作业 2.3.1、筛选11月自行车交易数据 赋予变量为ga...

  • 自行车业务分析 目录

    一、自行车整体销售表现 二、2019年11月自行车地域销售表现 三、2019年11月自行车产品销售表现 四、用户行...

  • 自行车业务分析 1.2

    1.2、自行车整体销售量表现 作业 1.2.1、聚合每月订单数量和销售金额,具体groupby创建一个新的对象,需...

  • 自行车业务分析 1.1

    一、自行车整体销售表现 1.1、从数据库读取源数据:dw_customer_order 作业 1.1.1、从Mys...

网友评论

      本文标题:自行车业务分析 3.3

      本文链接:https://www.haomeiwen.com/subject/psyptktx.html