python应用实例分析

发布时间:2022-04-25 11:01:45 作者:iii
来源:亿速云 阅读:236

本文小编为大家详细介绍“python应用实例分析”,内容详细,步骤清晰,细节处理妥当,希望这篇“python应用实例分析”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

在本季度中,求买合生元益生菌带动了多少奶粉新客

python应用实例分析


#naifen_vipflow.columnsss1= naifen_vipflow[[ 'flow_no','shopid_cardid','item_name']].rename(columns={'item_name':'item_name_naifen'})ss2 = ysj_vipflow[['flow_no','item_name']].rename(columns={'item_name':'item_name_ysj'})flow_no_naifen_ysj= ss1.merge(ss2, on='flow_no')  # 同时购买益生菌和奶粉的 订单 和会员
#flow_no_naifen_ysjformer_quarter_start_end=['2019-10-01 00:00:00','2020-01-01 00:00:00']after_quarter_start_end=['2020-01-01 00:00:00','2020-04-01 00:00:00'] groupby_list_vip =['shopid_cardid','shopid_branch','段位']groupby_list_branch=['shopid_branch','段位']#naifen_vipflow.columns#奶粉新客 #每个会员第一次购买 , 也就是 新客的流水saleflow= naifen_vipflowsaleflow_first = saleflow.groupby(groupby_list_vip).oper_date.min().reset_index().rename(columns={'oper_date':'date_1st'})# 挑选出 前面季度的新客former_new =saleflow_first[(saleflow_first['date_1st']<pd.to_datetime(former_quarter_start_end[1]))&(saleflow_first['date_1st']>pd.to_datetime(former_quarter_start_end[0]))]# 后一季度的新客 ,也就是本季度after_new =saleflow_first[(saleflow_first['date_1st']<pd.to_datetime(after_quarter_start_end[1]))&(saleflow_first['date_1st']>pd.to_datetime(after_quarter_start_end[0]))]#挑选出 后一季度的流水,也就是本季度after_flow  =  saleflow[(saleflow['oper_date']<pd.to_datetime(after_quarter_start_end[1]))&(saleflow['oper_date']>pd.to_datetime(after_quarter_start_end[0]))]##后一季度新客中, 同时买了奶粉和益生菌的订单号after_new_naifen_ysj= after_new.merge(flow_no_naifen_ysj)#.shopid_cardid.nunique()

整理为函数


def ysj_naifen_new(ysj_hsy_vipflow, naifen_vipflow,                    former_quarter_start_end=['2019-10-01 00:00:00','2020-01-01 00:00:00'] ,                   after_quarter_start_end=['2020-01-01 00:00:00','2020-04-01 00:00:00'] ,                   groupby_list_vip =['shopid_cardid','shopid_branch','段位']):        """    参数  :    ysj_hsy_vipflow: 益生菌的会员流水    naifen_vipflow : 奶粉 会员流水    former_quarter_start_end:上一时间段的范围     after_quarter_start_end : 下一时间段的范围     groupby_list_vip : 会员级别的分组,包含在groupby() 中,即groupby(groupby_list_vip)    """    ss1= naifen_vipflow[[ 'flow_no','shopid_cardid','item_name']].rename(columns={'item_name':'item_name_naifen'})    ss2 = ysj_vipflow[['flow_no','item_name']].rename(columns={'item_name':'item_name_ysj'})    flow_no_naifen_ysj= ss1.merge(ss2, on='flow_no')  # 同时购买合生元益生菌和 奶粉的订单号 商品名称        saleflow= naifen_vipflow    saleflow_first = saleflow.groupby(groupby_list_vip).oper_date.min().reset_index().rename(columns={'oper_date':'date_1st'})    # 挑选出 前面季度的新客    former_new =saleflow_first[(saleflow_first['date_1st']<pd.to_datetime(former_quarter_start_end[1]))&(saleflow_first['date_1st']>pd.to_datetime(former_quarter_start_end[0]))]    # 后一季度的新客    after_new =saleflow_first[(saleflow_first['date_1st']<pd.to_datetime(after_quarter_start_end[1]))&(saleflow_first['date_1st']>pd.to_datetime(after_quarter_start_end[0]))]    #挑选出 后一季度的流水    after_flow  =  saleflow[(saleflow['oper_date']<pd.to_datetime(after_quarter_start_end[1]))&(saleflow['oper_date']>pd.to_datetime(after_quarter_start_end[0]))]    ##后一季度新客中, 买了奶粉和益生菌的    after_new_naifen_ysj= after_new.merge(flow_no_naifen_ysj)#.shopid_cardid.nunique()        return after_new_naifen_ysj

python应用实例分析

对结果中的会员id 计数

读到这里,这篇“python应用实例分析”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. Python分支语句与循环语句应用实例分析
  2. JavaThreadLocal类应用实战的实例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python

上一篇:PHP中如何生成html文件

下一篇:Python怎么解决商品的铺货率问题

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》