這篇文章主要介紹“python怎么計算回購率”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“python怎么計算回購率”文章能幫助大家解決問題。
公司主營業(yè)務:網(wǎng)站設計、做網(wǎng)站、移動網(wǎng)站開發(fā)等業(yè)務。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出宜州免費做網(wǎng)站回饋大家。
計算 A時間段的新客 在B時間段的回購率
def huigou(saleflow,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','段位']):
#每個第一次購買 , 也就是 新客的流水
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_flow = saleflow[(saleflow['oper_date']<pd.to_datetime(after_quarter_start_end[1]))&(saleflow['oper_date']>pd.to_datetime(after_quarter_start_end[0]))]
## join 出 前面季度會員在后一季度的流水
fugou_flow = former_new.merge(after_flow,how='right')
# 計數(shù)
former_NEW_count=saleflow_first.groupby(groupby_list_branch).shopid_cardid.nunique().reset_index()\
.rename(columns={'shopid_cardid':'shopid_cardid_new_count'})
after_BACK_count= fugou_flow.groupby(groupby_list_branch).shopid_cardid.nunique().reset_index().\
rename(columns={'shopid_cardid':'shopid_cardid_back_count'})
df = former_NEW_count.merge(after_BACK_count,how='left')
return df
這個函數(shù)可以用來某月新客在次月的回購率, 如果要計算多個月的回購率,則需要循環(huán)。
首先生成 月份列表 ,月份間隔 為1 , 回購率列名 叫做 'next_'+ str(n_space)+'_month_rebuy_rate'
新建空的dataframe
# 計算每個月的 次月回頭率 即1月回頭率import arrowmonth_list =[each.format('YYYY-MM-DD HH:mm:SS') for each in arrow.Arrow.range('month', arrow.get('2019-07-01 00:00:00','YYYY-MM-DD HH:mm:SS'), arrow.get('2020-05-01 00:00:00','YYYY-MM-DD HH:mm:SS'))]n_space=1huigou_name= 'next_'+ str(n_space)+'_month_rebuy_rate'df_empty =pd.DataFrame(columns=('pinpai', 'shopid_cardid_new_count', 'shopid_cardid_back_count',huigou_name, '當前月', 'shopId'))
下面開始循環(huán)
for i in range(len(month_list)-n_space-1):
print(i,'當前月:',month_list[i])
ss = huigou(yyp_vipflow ,former_quarter_start_end=[month_list[i],month_list[i+n_space]],
after_quarter_start_end= [ month_list[i+n_space] , month_list[i+n_space+1] ] ,
groupby_list_vip =['shopid_cardid','shopid_branch','pinpai'],
groupby_list_branch=['shopid_branch','pinpai'])
new_sum = ss.groupby(['pinpai']).shopid_cardid_new_count.sum().reset_index()
back_sum =ss.groupby(['pinpai']).shopid_cardid_back_count.sum().reset_index()
result = new_sum.merge(back_sum)
result[huigou_name] = result['shopid_cardid_back_count'] / result['shopid_cardid_new_count']
result['當前月'] =month_list[i][0:10]
result['shopId'] =shopId
df_empty=df_empty.append(result)
如果要計算本月新客在第二個月的回購率,則n_space=2
關于“python怎么計算回購率”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識,可以關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。
網(wǎng)頁題目:python怎么計算回購率
文章地址:http://aaarwkj.com/article20/igdcjo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供Google、品牌網(wǎng)站制作、網(wǎng)站收錄、關鍵詞優(yōu)化、品牌網(wǎng)站建設、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)