利用 Python 分析了某化妆品企业的销售情况,我得出的结论是?
作者:Cherich_sun
來(lái)源:公眾號(hào)「杰哥的IT之旅」ID:Jake_Internet
【導(dǎo)語(yǔ)】本篇文章是關(guān)于某化妝品企業(yè)的銷售分析。從分析思路思路開(kāi)始帶大家一步步的用python進(jìn)行分析,找出問(wèn)題,并提出解決方案的整個(gè)流程。
需求:希望全面了解此某妝品企業(yè)的銷售情況,幫助企業(yè)運(yùn)營(yíng)領(lǐng)導(dǎo)層了解企業(yè)整體銷售運(yùn)營(yíng)情況及商品銷售情況,為該企業(yè)的營(yíng)銷策略提供相對(duì)應(yīng)的建議和銷售策略。
業(yè)務(wù)分析流程
1、 場(chǎng)景(診斷現(xiàn)狀)
對(duì)象:用戶;銷售
關(guān)注點(diǎn):找到影響銷售的增長(zhǎng)因素
目標(biāo):發(fā)現(xiàn)問(wèn)題&提出解決方案
2、需求拆解
分析銷售趨勢(shì),找到影響企業(yè)營(yíng)收增長(zhǎng)的商品或區(qū)域
按月份銷售趨勢(shì)圖(整體)
商品銷售額對(duì)比(一級(jí)、二級(jí),找出最低、最高)
區(qū)域銷售額對(duì)比(下鉆:區(qū)、省,找出最低、最高)
探索不同商品的銷售狀況,為企業(yè)的商品銷售,提出策略建議
不同月份的各個(gè)產(chǎn)品的銷售額占比情況
產(chǎn)品相關(guān)分析
分析用戶特征、購(gòu)買頻率、留存率等
購(gòu)買頻率分布
復(fù)購(gòu)率(重復(fù)購(gòu)買用戶數(shù)量(兩天都有購(gòu)買過(guò)算重復(fù))/用戶數(shù)量)
同期群分析(按月)
3、代碼實(shí)現(xiàn)
獲取數(shù)據(jù)(excel)
為某化妝品企業(yè) 2019 年 1 月-2019 年 9 月每日訂單詳情數(shù)據(jù)和企業(yè)的商品信息數(shù)據(jù),包括兩個(gè)數(shù)據(jù)表,銷售訂單表和商品信息表。其中銷售訂單表為每個(gè)訂單的情況明細(xì),一個(gè)訂單對(duì)應(yīng)一次銷售、一個(gè)訂單可包含多個(gè)商品。
import?pandas?as?pd import?matplotlib.pyplot?as?plt import?matplotlib?as?mpl mpl.rcParams['font.family']?=?'SimHei' import?numpy?as?np import?warnings warnings.filterwarnings("ignore") data?=?pd.read_excel('C:/Users/cherich/Desktop/日化.xlsx',encoding='gbk') data.head() data_info?=?pd.read_excel('C:/Users/cherich/Desktop/日化.xlsx',encoding='gbk',sheet_name='商品信息表') data_info數(shù)據(jù)清洗和加工
data?=?data.dropna() #?訂購(gòu)數(shù)量結(jié)尾有字符'個(gè)'data['訂購(gòu)數(shù)量']?=?data['訂購(gòu)數(shù)量'].apply(lambda?x:str(x)[:-1]?if?str(x)[-1]?==?'個(gè)'?else?x) data['訂購(gòu)數(shù)量']?=?data['訂購(gòu)數(shù)量'].astype(int)#?訂購(gòu)數(shù)量結(jié)尾有字符'元' data['訂購(gòu)單價(jià)']?=?data['訂購(gòu)單價(jià)'].apply(lambda?x:str(x)[:-1]?if?str(x)[-1]?==?'元'?else?x) data['訂購(gòu)單價(jià)']?=?data['訂購(gòu)單價(jià)'].astype(int) #?日期里有特殊字符?2019#3#11 def?proess_date(df):pos?=?str(df).find('#')if?pos!=?-1:df?=?str(df).split('#')return?df[0]+'-'+df[1]+'-'+df[2]else:return?df#?res?=?proess_date(df?='2019#3#11') data['訂單日期']?=?data['訂單日期'].apply(proess_date) data['訂單日期']?=?data['訂單日期'].apply(lambda?x:str(x).replace('年','-').replace('月','-')?if?'年'?in?str(x)?else?x?) data['訂單日期']?=?pd.to_datetime(data['訂單日期'])? #data.info()data?=?data[data.duplicated()==False] data['所在省份'].nunique() data['月份']?=?data['訂單日期'].apply(lambda?x:str(x).split('-')[1]) data數(shù)據(jù)可視化
#?兩張表數(shù)據(jù)合并 total_data?=?pd.merge(data,data_info,on='商品編號(hào)',how='left') total_datagroups?=?data.groupby('月份') x?=?[each[0]?for?each?in?groups] y?=?[each[1].金額.sum()?for?each?in?groups] z?=?[each[1].金額.count()?for?each?in?groups] money_mean?=?data.金額.sum()/9 order_mean?=?data.金額.count()/9plt.figure(figsize=(18,?10),?dpi=80) plt.subplot(221) plt.plot(x,?y,linewidth=2) plt.axvspan('07',?'08',?color='#EE7621',?alpha=0.3) plt.axhline(money_mean,?color='#EE7621',?linestyle='--',linewidth=1) plt.title("每月銷售額趨勢(shì)圖",color='#4A708B',fontsize=24) plt.ylabel("金額/(億)",fontsize=16)plt.subplot(222) plt.plot(x,?z,?linewidth=2,?color?=?'#EE7621') plt.axvline('07',?color='#4A708B',?linestyle='--',linewidth=1) plt.axhline(order_mean,?color='#4A708B',?linestyle='--',linewidth=1) plt.title("每月訂單量趨勢(shì)圖",color='#4A708B',fontsize=24) plt.ylabel("訂單/(單)",fontsize=16) plt.show()圖表說(shuō)明:從整體來(lái)看,銷售額和訂單量從4月開(kāi)始大幅度上升,均高于均值;8月份開(kāi)始呈下降趨勢(shì),處于均值水平。
groups_category=?total_data.groupby(['月份','商品大類']) category1?=?[] category2?=?[] for?i,j?in?groups_category: #?????print(i,j.月份.count())if?i[1]=='彩妝':category1.append(j.金額.sum())else:category2.append(j.金額.sum()) labels?=?x xticks?=?np.arange(len(labels)) width?=?0.5 p?=?np.arange(len(labels)) fig,?ax?=?plt.subplots(figsize=(18,8)) rects1?=?ax.bar(p?-?width/2,?category1,width,?label='彩妝',color='#FFEC8B') rects2?=?ax.bar(p?+?width/2,?category2,?width,?label='護(hù)膚品',color='#4A708B')ax.set_ylabel('銷售額/(億)') ax.set_title('每月護(hù)膚品和彩妝的銷售額對(duì)比圖(大類)') ax.set_xticks(xticks) ax.set_xticklabels(labels) ax.legend()plt.show()圖表說(shuō)明:護(hù)膚品需求滿足大多數(shù)人,明顯高于彩妝。并且5月—8月是護(hù)膚品需求旺季。相比彩妝的變化不明顯。
groups_categorys=?total_data.groupby('商品小類') x?=?[each[0]?for?each?in?groups_categorys] y?=?[each[1].金額.sum()?for?each?in?groups_categorys]fig?=?plt.figure(figsize=(18,8),dpi=80) plt.title('各個(gè)品類的銷售額對(duì)比圖',color='#4A708B',fontsize=24) plt.ylabel('銷售額(元)',fontsize=15) colors?=?['#6699cc','#4A708B','#CDCD00','#DAA520','#EE7621','#FFEC8B','#CDCD00','#4A708B','#6699cc','#DAA520','#4A708B','#FFEC8B'] for?i,?group_name?in?enumerate(groups_categorys):lin1?=plt.bar(group_name[0],?group_name[1].金額.sum(),width=0.8,color=colors[i])for?rect?in?lin1:height?=?rect.get_height()plt.text(rect.get_x()+rect.get_width()/2,?height+1,?int(height),ha="center",fontsize=12)plt.xticks(fontsize=15) plt.grid() plt.show()圖表說(shuō)明:面膜的銷售額第一,其次是面霜、爽膚水。銷售額最低的是蜜粉,眼影。
total_data?=?total_data.dropna() total_data['所在區(qū)域']?=?total_data['所在區(qū)域'].apply(lambda?x:str(x).replace('男區(qū)','南區(qū)').replace('西?區(qū)','西區(qū)')) groups_area=?total_data.groupby(['所在區(qū)域','商品小類']) results?=?{}? for?i,j??in?groups_area:?money?=?int(j.金額.sum())if?i[0]?in?results.keys():results[i[0]][i[1]]?=?money?????else:results[i[0]]?=?{}???for?cate?in?category_names:results[i[0]][cate]?=?0results[i[0]]['口紅']?=?moneyresults=?{key_data:list(values_data.values())?for?key_data,values_data?in?results.items()}def?survey1(results,?category_names):labels?=?list(results.keys())data?=?np.array(list(results.values()))data_cum?=?data.cumsum(axis=1)category_colors?=?plt.get_cmap('RdYlGn')(np.linspace(0.15,?0.85,?data.shape[1]))fig,?ax?=?plt.subplots(figsize=(25,8))ax.invert_yaxis()ax.xaxis.set_visible(False)ax.set_xlim(0,?np.sum(data,?axis=1).max())for?i,?(colname,?color)?in?enumerate(zip(category_names,?category_colors)):widths?=?data[:,?i]starts?=?data_cum[:,?i]?-?widthsax.barh(labels,?widths,?left=starts,?height=0.5,label=colname,?color=color)xcenters?=?starts?+?widths?/?2r,?g,?b,?_?=?colortext_color?=?'white'?if?r?*?g?*?b?<?0.5?else?'darkgrey'for?y,?(x,?c)?in?enumerate(zip(xcenters,?widths)):ax.text(x,?y,?str(int(c)),?ha='center',?va='center',color=text_color)ax.legend(ncol=len(category_names),?bbox_to_anchor=(0,?1),loc='lower?left',?fontsize='small')return?fig,?ax survey1(results,?category_names) plt.show()圖表說(shuō)明:東部地區(qū)占市場(chǎng)份額的35%左右,份額最低的是西部地區(qū)。
area_names?=?list(total_data.商品小類.unique()) groups_priv=?total_data.groupby(['所在省份','商品小類']) results?=?{}? for?i,j??in?groups_priv:?money?=?int(j.金額.sum())if?i[0]?in?results.keys():results[i[0]][i[1]]?=?money?????else:results[i[0]]?=?{}???for?cate?in?category_names:results[i[0]][cate]?=?0results[i[0]]['口紅']?=?moneyresults=?{key_data:list(values_data.values())?for?key_data,values_data?in?results.items()}def?survey2(results,?category_names):labels?=?list(results.keys())data?=?np.array(list(results.values()))data_cum?=?data.cumsum(axis=1)category_colors?=?plt.get_cmap('RdYlGn')(np.linspace(0.15,?0.85,?data.shape[1]))fig,?ax?=?plt.subplots(figsize=(25,20))ax.invert_yaxis()ax.xaxis.set_visible(False)ax.set_xlim(0,?np.sum(data,?axis=1).max())for?i,?(colname,?color)?in?enumerate(zip(category_names,?category_colors)):widths?=?data[:,?i]starts?=?data_cum[:,?i]?-?widthsax.barh(labels,?widths,?left=starts,?height=0.5,label=colname,?color=color)xcenters?=?starts?+?widths?/?2ax.legend(ncol=len(category_names),?bbox_to_anchor=(0,?1),loc='lower?left',?fontsize='small')return?fig,?ax survey2(results,?area_names) plt.show()圖表說(shuō)明:江蘇銷售額第一,其次是廣東省;銷售額最低的是寧夏、內(nèi)蒙、海南
import?numpy?as?np import?matplotlib.pyplot?as?plt category_names?=?list(total_data.商品小類.unique()) groups_small_category=?total_data.groupby(['月份','商品小類']) results?=?{}? for?i,j??in?groups_small_category:?money?=?int(j.金額.sum())if?i[0]?in?results.keys():results[i[0]][i[1]]?=?money?????else:results[i[0]]?=?{}???for?cate?in?category_names:results[i[0]][cate]?=?0results[i[0]]['口紅']?=?moneyresults=?{key_data:list(values_data.values())?for?key_data,values_data?in?results.items()} def?survey(results,?category_names):labels?=?list(results.keys())data?=?np.array(list(results.values()))data_cum?=?data.cumsum(axis=1)category_colors?=?plt.get_cmap('RdYlGn')(np.linspace(0.15,?0.85,?data.shape[1]))fig,?ax?=?plt.subplots(figsize=(25,8))ax.invert_yaxis()ax.xaxis.set_visible(False)ax.set_xlim(0,?np.sum(data,?axis=1).max())for?i,?(colname,?color)?in?enumerate(zip(category_names,?category_colors)):widths?=?data[:,?i]starts?=?data_cum[:,?i]?-?widthsax.barh(labels,?widths,?left=starts,?height=0.5,label=colname,?color=color)xcenters?=?starts?+?widths?/?2#?????????r,?g,?b,?_?=?color #?????????text_color?=?'white'?if?r?*?g?*?b?<?0.5?else?'darkgrey' #?????????for?y,?(x,?c)?in?enumerate(zip(xcenters,?widths)): #?????????????ax.text(x,?y,?str(int(c)),?ha='center',?va='center')ax.legend(ncol=len(category_names),?bbox_to_anchor=(0,?1),loc='lower?left',?fontsize='small')return?fig,?ax survey(results,?category_names)plt.show()圖表說(shuō)明:眼霜、爽膚水、面膜:4,5,6,7,8月份需求量最大;粉底、防曬霜、隔離霜、睫毛膏、蜜粉1,2,3月份需求量最大。
data_user_buy=total_data.groupby('客戶編碼')['訂單編碼'].count() data_user_buy plt.figure(figsize=(10,4),dpi=80) plt.hist(data_user_buy,color='#FFEC8B')plt.title('用戶購(gòu)買次數(shù)分布',fontsize=16) plt.xlabel('購(gòu)買次數(shù)') plt.ylabel('用戶數(shù)') plt.show()圖表說(shuō)明:大部分用戶購(gòu)買次數(shù)在10次-35次之間,極少部分用戶購(gòu)買次數(shù)80次以上
date_rebuy=total_data.groupby('客戶編碼')['訂單日期'].apply(lambda?x:len(x.unique())).rename('rebuy_count') date_rebuy print('復(fù)購(gòu)率:',round(date_rebuy[date_rebuy>=2].count()/date_rebuy.count(),4)) total_data['時(shí)間標(biāo)簽']?=?total_data['訂單日期'].astype(str).str[:7] total_data?=?total_data[total_data['時(shí)間標(biāo)簽']!='2050-06'] total_data['時(shí)間標(biāo)簽'].value_counts().sort_index() total_data?=?total_data.sort_values(by='時(shí)間標(biāo)簽') month_lst?=?total_data['時(shí)間標(biāo)簽'].unique() final=pd.DataFrame() final #引入時(shí)間標(biāo)簽 for?i?in?range(len(month_lst)-1):#構(gòu)造和月份一樣長(zhǎng)的列表,方便后續(xù)格式統(tǒng)一count?=?[0]?*?len(month_lst)#篩選出當(dāng)月訂單,并按客戶昵稱分組target_month?=?total_data.loc[total_data['時(shí)間標(biāo)簽']==month_lst[i],:]target_users?=?target_month.groupby('客戶編碼')['金額'].sum().reset_index()#如果是第一個(gè)月份,則跳過(guò)(因?yàn)椴恍枰蜌v史數(shù)據(jù)驗(yàn)證是否為新增客戶)if?i==0:new_target_users?=?target_month.groupby('客戶編碼')['金額'].sum().reset_index()else:#如果不是,找到之前的歷史訂單history?=?total_data.loc[total_data['時(shí)間標(biāo)簽'].isin(month_lst[:i]),:]#篩選出未在歷史訂單出現(xiàn)過(guò)的新增客戶new_target_users?=?target_users.loc[target_users['客戶編碼'].isin(history['客戶編碼'])?==?False,:]#當(dāng)月新增客戶數(shù)放在第一個(gè)值中count[0]?=?len(new_target_users)#以月為單位,循環(huán)遍歷,計(jì)算留存情況for?j,ct?in?zip(range(i?+?1,len(month_lst)),range(1,len(month_lst))):#下一個(gè)月的訂單next_month?=?total_data.loc[total_data['時(shí)間標(biāo)簽']?==?month_lst[j],:]next_users?=?next_month.groupby('客戶編碼')['金額'].sum().reset_index()#計(jì)算在該月仍然留存的客戶數(shù)量isin?=?new_target_users['客戶編碼'].isin(next_users['客戶編碼']).sum()count[ct]?=?isin#格式轉(zhuǎn)置result?=?pd.DataFrame({month_lst[i]:count}).T#合并final?=?pd.concat([final,result])final.columns?=?['當(dāng)月新增','+1月','+2月','+3月','+4月','+5月','+6月','+7月','+8月'] result?=?final.divide(final['當(dāng)月新增'],axis=0).iloc[:] result['當(dāng)月新增']?=?final['當(dāng)月新增'] result.round(2)同期群分析
圖表說(shuō)明:由新增用戶情況看,新用戶逐月明顯減少;留存率在1月-5月平均在50%,6月-8月留存率上升明顯。
結(jié)論與建議
1、從銷售額趨勢(shì)來(lái)看,整體是上升趨勢(shì),但是從8月份銷售額突然下降,可能因?yàn)榈降?#xff0c;需進(jìn)一步確認(rèn)原因;
2、商品銷售額,用戶對(duì)護(hù)膚品具有強(qiáng)烈的需求,尤其是面膜,爽膚水、面霜、眼霜。較低需求的是蜜粉。可以把高需求產(chǎn)品,組合成禮盒等套裝活動(dòng);
3、商品銷售建議:眼霜、爽膚水、面膜:4,5,6,7,8月需求最大;粉底、防曬霜、隔離霜、睫毛膏、蜜粉1,2,3月需求最大。以上說(shuō)明用戶購(gòu)買特定產(chǎn)品具有周期性;
4、從地域來(lái)看,東部地區(qū)是消費(fèi)的主力軍,其中江蘇省、廣東省、浙江省的銷售額最大。可以增大市場(chǎng)投放量;也可以考慮在該地區(qū)建倉(cāng),節(jié)省物流等成本;
5、用戶:重點(diǎn)維護(hù)購(gòu)買次數(shù)在10次-35次之間的用戶群體;
6、留存率在99%,證明用戶對(duì)產(chǎn)品有一定的依賴性;
7、從同期群分析來(lái)看,新用戶明顯減少,應(yīng)考慮拉新,增加平臺(tái)新用戶(主播帶貨等);
推薦閱讀 誤執(zhí)行了rm -fr /*之后,除了跑路還能怎么辦?!程序員必備58個(gè)網(wǎng)站匯總大幅提高生產(chǎn)力:你需要了解的十大Jupyter Lab插件總結(jié)
以上是生活随笔為你收集整理的利用 Python 分析了某化妆品企业的销售情况,我得出的结论是?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 5.2k Star!一款 Python
- 下一篇: 微软 VS Code 有 1400 万用