In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you how Python solves the problems of the number of new customers, the number of buybacks and the total number of people. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Read the pipeline
Saleflow= pd.read_csv ('pipelined. CSV', index_col=0)
The running water of synbiotic probiotics was screened.
# processing field yyp_saleflow=saleflow [saleflow ['cls'] = =' nutrition'] yyp_saleflow=saleflow [saleflow ['custype'] = =' vip'] ysj_saleflow = yyp_ saleflow [yyp _ saleflow ['cls2'] = =' probiotics'] ysj_saleflow ['pinpai'] = ysj_saleflow.apply (pinpai_class_new,axis=1) # print (' probiotic flow number') Ysj_saleflow.shape [0]) ysj_saleflow= ysj_ Saleflow [ysj _ saleflow ['pinpai'] = =' synbiotic'] # print ('number of probiotics', ysj_saleflow.shape [0])
Ask each member to buy synbiotic probiotics for the first time, so as to screen out new customers in a certain quarter.
# time when members first purchased probiotics ysj_first = ysj_saleflow.groupby (['shopid_cardid']). Oper_date.min (). Reset_index (). Rename (columns= {' oper_date':'oper_date_first'}) ysj_first ['oper_date_first'] = pd.to_datetime (ysj_first [' oper_date_first']) # New guest ysj_new_Q1= ysj_first in each quarter [(ysj_first ['oper_date_first'])
< pd.to_datetime('2020-04-01 00:00:00'))&(ysj_first['oper_date_first'] >Pd.to_datetime ('2020-01-01 00 ysj_first [' oper_date_first'])] ysj_new_Q3= ysj_first
< pd.to_datetime('2019-10-01 00:00:00'))&(ysj_first['oper_date_first'] >Pd.to_datetime ('2019-07-01 00 ysj_new_Q4 ysj_first [(ysj_first [' oper_date_first']))
< pd.to_datetime('2020-01-01 00:00:00'))&(ysj_first['oper_date_first'] >Pd.to_datetime ('2019-10-0100GRV 0000')]
For example, the new customers of Q3 are
In this way, we have new customers for every quarter, ID.
After counting the regular customers, the regular customers are defined as the members who bought Synergy in both the third quarter and the second quarter, and all of them only use the id of the flow member of the third quarter and the id of the second quarter to inner join.
Ysj_saleflow2019=ysj_saleflow.query ('year==2019') ysj_saleflow2019Q2_id=ysj_ saleflow 2019 [YSJ _ saleflow2019.month.isin ([4je 5je 6])] [' shopid_cardid']] ysj_saleflow2019Q3_id=ysj_ Saleflow 2019 [YSJ _ saleflow2019.month.isin ([7spar8]) 9])] [['shopid_cardid']] ysj_saleflow2019Q4_id=ysj_ saleflow 2019 [ysj _ saleflow2019.month.isin ([10Me11 shopid_cardid' 12])] [[' shopid_cardid']] ysj_Q3_old_id= (ysj_saleflow2019Q2_id.merge (ysj_saleflow2019Q3_id)) .drop_duplicates ()
Then calculate how many new customers of Q3 have bought synbiotic probiotics in Q4, that is, buyback.
The idea is to take Q4 member id and Q3 newcomer id inner join
# Q3 number of new customers repurchased at the end of the year Q3new_to_Q4 = (ysj_saleflow2019Q4_id.merge (ysj_new_Q3)) .shopid_cardid.nunique ()
Finally, count the number of people and create a dataframe
# number of new customers Q3_new=ysj_new_Q3.shopid_cardid.nunique () # Q3 Total number of probiotics Q3 YSJJ total = ysj_saleflow2019Q3_id.shopid_cardid.nunique () # number of regular customers ysj_Q3_old_id= (ysj_saleflow2019Q2_id.merge (ysj_saleflow2019Q3_id)). Drop_duplicates () Q3_old=ysj_Q3_old_id.shopid_cardid.nunique () #. Reset_index () # Q3 number of regular customers # Q3 new customers Number of buybacks at the end of the year Q3new_to_Q4 = (ysj_saleflow2019Q4_id.merge (ysj_new_Q3)). Shopid_cardid.nunique () # # create dataframedata = {'total members of Q3 probiotics': [Q3_YSJ_total] 'Q3 new customers': [Q3_new],'Q3 regular customers': [Q3_old],'Q3 new customers repurchased at the end of the year': [Q3new_to_Q4], 'shopId': [shopId]} frame = pd.DataFrame (data, columns = [' total number of Q3 probiotics','Q3 new customers','Q3 regular customers' 'The number of Q3 new customers repurchased at the end of the year', 'shopId'])
Only one chain is calculated here. If you calculate multiple chains, you can cycle through the list of chains.
Df.append (). To do this is to create an empty dataframe before the loop
Df_empty = pd.DataFrame (columns= ('total members of Q3 probiotics', 'number of Q3 new customers', 'number of Q3 regular customers', 'number of Q3 new customers repurchased at the end of the year', 'shopId'))
Each cycle causes df_empty to add a chain of data, that is,
Df_empty=df_empty.append (frame,ignore_index=True)
Pseudo code:
Df_empty = pd.DataFrame (columns= ('total members of Q3 probiotics', 'number of Q3 new customers', 'number of Q3 regular customers', 'number of Q3 new customers repurchased at the end of the year', 'shopId')) for list of a chain in chain: calculate a chain and get frame
Df_empty= df_empty.append (frame, ignore_index=True) above is all the contents of this article entitled "how does Python solve the problem of the number of new customers, the number of buybacks and the total number of people". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.