您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“python應用實例分析”,內容詳細,步驟清晰,細節處理妥當,希望這篇“python應用實例分析”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。
在本季度中,求買合生元益生菌帶動了多少奶粉新客
#naifen_vipflow.columns
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') # 同時購買益生菌和奶粉的 訂單 和會員
#flow_no_naifen_ysj
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','段位']
groupby_list_branch=['shopid_branch','段位']
#naifen_vipflow.columns
#奶粉新客
#每個會員第一次購買 , 也就是 新客的流水
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()
整理為函數
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
對結果中的會員id 計數
讀到這里,這篇“python應用實例分析”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。