您好,登錄后才能下訂單哦!
這篇文章主要介紹“python購物實例分析”,在日常操作中,相信很多人在python購物實例分析問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”python購物實例分析”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
任務: 合生元品牌的奶粉會員的營養品子品和其他大類的購物籃分析
思路:
合生元奶粉流水與營養品二級品類流水 依據流水號left join, 再與其他大類流水left join, 且大類的類別名稱要更改
獲得合生元奶粉(品類cls)和 營養品二級品類(品類cls2)流水,并left join
zhenjia= saleflow.item_name.str.contains('奶粉')|saleflow.item_brandname.str.contains('奶粉')|saleflow.cls.str.contains('奶粉')|saleflow.cls2.str.contains('奶粉')&saleflow.c1.str.contains('奶粉')&saleflow.c2.str.contains('奶粉')|saleflow.c3.str.contains('奶粉')
naifen_saleflow=saleflow[zhenjia]
naifen_saleflow['品牌'] = naifen_saleflow.apply(pinpai_class_pro,axis=1) # 這些函數只能針對奶粉數據
naifen_vipflow =naifen_saleflow[(naifen_saleflow['card_id']!=np.nan) & (naifen_saleflow['custype']=='vip')&(naifen_saleflow['sale_money']>0)]
yyp_saleflow= saleflow[saleflow['cls']=='營養品']
#saleflow_naifen_hsy = saleflow_naifen[saleflow_naifen['品牌']=='合生元']
YYP =yyp_saleflow[[ 'branch_no','card_id','flow_no','cls2', 'shopid_cardid','age']]
saleflow_heshengyuan_naifen = naifen_saleflow[naifen_saleflow['品牌']=='合生元']
HSY_NAIFEN=saleflow_heshengyuan_naifen[[ 'shopId','branch_no', 'card_id','flow_no', 'cls', 'shopid_cardid']]
合生元奶粉和營養品左連接
HSY_NAIFEN_YSJ = HSY_NAIFEN.merge(YYP, how='left')
再獲得各大類(cls 中的用品、玩具、輔食等)的流水,并且各大類的里面要重命名,比如 用品的 cls 列名要重命名為 cls_yongpin, 依次類推
yongpin_saleflow= saleflow[saleflow['cls']=='用品']
YONGPING =yongpin_saleflow[[ 'branch_no','card_id','flow_no','cls', 'shopid_cardid','age']].\
rename(columns={'cls':'cls_yongpin'})
zhipin_saleflow= saleflow[saleflow['cls']=='紙品']
ZHIPIN =zhipin_saleflow[[ 'branch_no','card_id','flow_no','cls', 'shopid_cardid','age']].\
rename(columns={'cls':'cls_zhipin'})
wanju_saleflow= saleflow[saleflow['cls']=='玩具']
WANJU =wanju_saleflow[[ 'branch_no','card_id','flow_no','cls', 'shopid_cardid','age']].\
rename(columns={'cls':'cls_wanju'})
mianpin_saleflow= saleflow[saleflow['cls']=='棉品']
MIANPIN = mianpin_saleflow[[ 'branch_no','card_id','flow_no','cls', 'shopid_cardid','age']].\
rename(columns={'cls':'cls_mianpin'})
fushi_saleflow= saleflow[saleflow['cls']=='輔食']
FUSHI = fushi_saleflow[[ 'branch_no','card_id','flow_no','cls', 'shopid_cardid','age']].\
rename(columns={'cls':'cls_fushi'})
fuwu_saleflow= saleflow[saleflow['cls']=='服務']
FUWU = fuwu_saleflow[[ 'branch_no','card_id','flow_no','cls', 'shopid_cardid','age']].\
rename(columns={'cls':'cls_fuwu'})
chechuang_saleflow= saleflow[saleflow['cls']=='車床']
CHECHUANG = fushi_saleflow[[ 'branch_no','card_id','flow_no','cls', 'shopid_cardid','age']].\
rename(columns={'cls':'cls_chechuang'})
最后合并
RESUT =(((((HSY_NAIFEN_YSJ.merge(YONGPIN,how='left')).merge(ZHIPIN,how='left'))\ .merge(MIANPIN,how='left')).merge(FUSHI,how='left')).merge(FUWU,how='left')).\merge(CHECHUANG,how='left').merge(WANJU,how='left')
連接各類別字符串,得到訂單購物籃
RESULT =RESUT.replace(np.nan,'')RESULT['訂單購物籃']= RESULT['cls']+'-'+RESULT['cls2']+'-'+RESULT['cls_zhipin'] + \'-'+ RESULT['cls_fuwu'] + '-'+ RESULT['cls_mianpin']+'-'+\RESULT['cls_chechuang']+'-'+RESULT['cls_yongpin']+'-'+ RESULT['cls_wanju'] +'-'+ RESULT['cls_fushi']
到此,關于“python購物實例分析”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。