利用 Python 分析了某化妝品企業的銷售情況,我得出的結論是?

{"type":"doc","content":[{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"作者:Cherich_sun","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"來源:公衆號「傑哥的IT之旅」ID:Jake_Internet","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本文爲讀者投稿","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"【導語】本篇文章是關於某化妝品企業的銷售分析。從分析思路思路開始帶大家一步步的用python進行分析,找出問題,並提出解決方案的整個流程。","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/d4/d4351b7f14842ab9c1175e37d40244fa.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"需求:希望全面瞭解此某妝品企業的銷售情況,幫助企業運營領導層瞭解企業整體銷售運營情況及商品銷售情況,爲該企業的營銷策略提供相對應的建議和銷售策略。","attrs":{}}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"業務分析流程","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"1、 場景(診斷現狀)","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對象:用戶;銷售","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"關注點:找到影響銷售的增長因素","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目標:發現問題&提出解決方案","attrs":{}}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2、需求拆解","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"分析銷售趨勢,找到影響企業營收增長的商品或區域","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"按月份銷售趨勢圖(整體)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"商品銷售額對比(一級、二級,找出最低、最高)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"區域銷售額對比(下鑽:區、省,找出最低、最高)","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"探索不同商品的銷售狀況,爲企業的商品銷售,提出策略建議","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"不同月份的各個產品的銷售額佔比情況","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"產品相關分析","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"分析用戶特徵、購買頻率、留存率等","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"購買頻率分佈","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"復購率(重複購買用戶數量(兩天都有購買過算重複)/用戶數量)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同期羣分析(按月)","attrs":{}}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"3、代碼實現","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"獲取數據(excel)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"爲某化妝品企業 2019 年 1 月-2019 年 9 月每日訂單詳情數據和企業的商品信息數據,包括兩個數據表,銷售訂單表和商品信息表。其中銷售訂單表爲每個訂單的情況明細,一個訂單對應一次銷售、一個訂單可包含多個商品。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib as mpl\nmpl.rcParams['font.family'] = 'SimHei'\nimport numpy as np\nimport warnings\nwarnings.filterwarnings(\"ignore\")\ndata = pd.read_excel('C:/Users/cherich/Desktop/日化.xlsx',encoding='gbk')\ndata.head()","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ed/ed13002176942e91b853ba6c109f6171.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"data_info = pd.read_excel('C:/Users/cherich/Desktop/日化.xlsx',encoding='gbk',sheet_name='商品信息表')\ndata_info","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/e5/e5a0e97e599bdd71b18d5fd35a9060fd.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"數據清洗和加工","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"data = data.dropna()\n# 訂購數量結尾有字符'個'\n\ndata['訂購數量'] = data['訂購數量'].apply(lambda x:str(x)[:-1] if str(x)[-1] == '個' else x)\ndata['訂購數量'] = data['訂購數量'].astype(int)\n\n# 訂購數量結尾有字符'元'\ndata['訂購單價'] = data['訂購單價'].apply(lambda x:str(x)[:-1] if str(x)[-1] == '元' else x)\ndata['訂購單價'] = data['訂購單價'].astype(int)\n# 日期裏有特殊字符 2019#3#11\ndef proess_date(df):\n pos = str(df).find('#')\n if pos!= -1:\n df = str(df).split('#')\n return df[0]+'-'+df[1]+'-'+df[2]\n else:\n return df\n\n# res = proess_date(df ='2019#3#11')\ndata['訂單日期'] = data['訂單日期'].apply(proess_date)\ndata['訂單日期'] = data['訂單日期'].apply(lambda x:str(x).replace('年','-').replace('月','-') if '年' in str(x) else x )\ndata['訂單日期'] = pd.to_datetime(data['訂單日期']) \n#data.info()\n\ndata = data[data.duplicated()==False]\ndata['所在省份'].nunique()\ndata['月份'] = data['訂單日期'].apply(lambda x:str(x).split('-')[1])\ndata","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c2/c21e769cab4ab72f72183e57efa2b3de.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"數據可視化","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"# 兩張表數據合併\ntotal_data = pd.merge(data,data_info,on='商品編號',how='left')\ntotal_data","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/f4/f4c7ff78a35f157a9de46e859d98d5ed.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"groups = data.groupby('月份')\nx = [each[0] for each in groups]\ny = [each[1].金額.sum() for each in groups]\nz = [each[1].金額.count() for each in groups]\nmoney_mean = data.金額.sum()/9\norder_mean = data.金額.count()/9\n\nplt.figure(figsize=(18, 10), dpi=80)\nplt.subplot(221)\nplt.plot(x, y,linewidth=2)\nplt.axvspan('07', '08', color='#EE7621', alpha=0.3)\nplt.axhline(money_mean, color='#EE7621', linestyle='--',linewidth=1)\nplt.title(\"每月銷售額趨勢圖\",color='#4A708B',fontsize=24)\nplt.ylabel(\"金額/(億)\",fontsize=16)\n\nplt.subplot(222)\nplt.plot(x, z, linewidth=2, color = '#EE7621')\nplt.axvline('07', color='#4A708B', linestyle='--',linewidth=1)\nplt.axhline(order_mean, color='#4A708B', linestyle='--',linewidth=1)\nplt.title(\"每月訂單量趨勢圖\",color='#4A708B',fontsize=24)\nplt.ylabel(\"訂單/(單)\",fontsize=16)\nplt.show()","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/94/948a21d296958f43014407858ec1d621.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖表說明:從整體來看,銷售額和訂單量從4月開始大幅度上升,均高於均值;8月份開始呈下降趨勢,處於均值水平。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"groups_category= total_data.groupby(['月份','商品大類'])\ncategory1 = []\ncategory2 = []\nfor i,j in groups_category:\n# print(i,j.月份.count())\n if i[1]=='彩妝':\n category1.append(j.金額.sum())\n else:\n category2.append(j.金額.sum())\nlabels = x\nxticks = np.arange(len(labels))\nwidth = 0.5\np = np.arange(len(labels))\nfig, ax = plt.subplots(figsize=(18,8))\nrects1 = ax.bar(p - width/2, category1,width, label='彩妝',color='#FFEC8B')\nrects2 = ax.bar(p + width/2, category2, width, label='護膚品',color='#4A708B')\n\n\nax.set_ylabel('銷售額/(億)')\nax.set_title('每月護膚品和彩妝的銷售額對比圖(大類)')\nax.set_xticks(xticks)\nax.set_xticklabels(labels)\nax.legend()\n\nplt.show()","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/f7/f75a8f6c36ddc1866567f3684e5b8892.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖表說明:護膚品需求滿足大多數人,明顯高於彩妝。並且5月—8月是護膚品需求旺季。相比彩妝的變化不明顯。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"groups_categorys= total_data.groupby('商品小類')\nx = [each[0] for each in groups_categorys]\ny = [each[1].金額.sum() for each in groups_categorys]\n\nfig = plt.figure(figsize=(18,8),dpi=80)\nplt.title('各個品類的銷售額對比圖',color='#4A708B',fontsize=24)\nplt.ylabel('銷售額(元)',fontsize=15)\ncolors = ['#6699cc','#4A708B','#CDCD00','#DAA520','#EE7621','#FFEC8B','#CDCD00','#4A708B','#6699cc','#DAA520','#4A708B','#FFEC8B']\nfor i, group_name in enumerate(groups_categorys):\n lin1 =plt.bar(group_name[0], group_name[1].金額.sum(),width=0.8,color=colors[i])\n for rect in lin1:\n height = rect.get_height()\n plt.text(rect.get_x()+rect.get_width()/2, height+1, int(height),ha=\"center\",\n fontsize=12)\n\nplt.xticks(fontsize=15)\nplt.grid()\nplt.show()","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/9d/9d4f2a0790323b19ad41248279289f03.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖表說明:面膜的銷售額第一,其次是面霜、爽膚水。銷售額最低的是蜜粉,眼影。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"total_data = total_data.dropna()\ntotal_data['所在區域'] = total_data['所在區域'].apply(lambda x:str(x).replace('男區','南區').replace('西 區','西區'))\ngroups_area= total_data.groupby(['所在區域','商品小類'])\nresults = {} \nfor i,j in groups_area: \n money = int(j.金額.sum())\n if i[0] in results.keys():\n results[i[0]][i[1]] = money \n else:\n results[i[0]] = {} \n for cate in category_names:\n results[i[0]][cate] = 0\n results[i[0]]['口紅'] = money\n\nresults= {key_data:list(values_data.values()) for key_data,values_data in results.items()}\n\ndef survey1(results, category_names):\n labels = list(results.keys())\n data = np.array(list(results.values()))\n\n data_cum = data.cumsum(axis=1)\n category_colors = plt.get_cmap('RdYlGn')(\n np.linspace(0.15, 0.85, data.shape[1]))\n fig, ax = plt.subplots(figsize=(25,8))\n ax.invert_yaxis()\n ax.xaxis.set_visible(False)\n ax.set_xlim(0, np.sum(data, axis=1).max())\n\n for i, (colname, color) in enumerate(zip(category_names, category_colors)):\n widths = data[:, i]\n starts = data_cum[:, i] - widths\n ax.barh(labels, widths, left=starts, height=0.5,\n label=colname, color=color)\n xcenters = starts + widths / 2\n\n r, g, b, _ = color\n text_color = 'white' if r * g * b < 0.5 else 'darkgrey'\n for y, (x, c) in enumerate(zip(xcenters, widths)):\n ax.text(x, y, str(int(c)), ha='center', va='center',color=text_color)\n ax.legend(ncol=len(category_names), bbox_to_anchor=(0, 1),\n loc='lower left', fontsize='small')\n\n return fig, ax\nsurvey1(results, category_names)\nplt.show()","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/6b/6b4a0377e492d3efce8f68a02c69b2d4.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖表說明:東部地區佔市場份額的35%左右,份額最低的是西部地區。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"area_names = list(total_data.商品小類.unique())\ngroups_priv= total_data.groupby(['所在省份','商品小類'])\nresults = {} \nfor i,j in groups_priv: \n money = int(j.金額.sum())\n if i[0] in results.keys():\n results[i[0]][i[1]] = money \n else:\n results[i[0]] = {} \n for cate in category_names:\n results[i[0]][cate] = 0\n results[i[0]]['口紅'] = money\n\nresults= {key_data:list(values_data.values()) for key_data,values_data in results.items()}\n\ndef survey2(results, category_names):\n labels = list(results.keys())\n data = np.array(list(results.values()))\n\n data_cum = data.cumsum(axis=1)\n category_colors = plt.get_cmap('RdYlGn')(\n np.linspace(0.15, 0.85, data.shape[1]))\n fig, ax = plt.subplots(figsize=(25,20))\n ax.invert_yaxis()\n ax.xaxis.set_visible(False)\n ax.set_xlim(0, np.sum(data, axis=1).max())\n\n for i, (colname, color) in enumerate(zip(category_names, category_colors)):\n widths = data[:, i]\n starts = data_cum[:, i] - widths\n ax.barh(labels, widths, left=starts, height=0.5,\n label=colname, color=color)\n xcenters = starts + widths / 2\n\n ax.legend(ncol=len(category_names), bbox_to_anchor=(0, 1),\n loc='lower left', fontsize='small')\n\n return fig, ax\nsurvey2(results, area_names)\nplt.show()","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/5e/5eb2c687b8e9af5f7b6425b78c2c87ea.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖表說明:江蘇銷售額第一,其次是廣東省;銷售額最低的是寧夏、內蒙、海南","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"import numpy as np\nimport matplotlib.pyplot as plt\ncategory_names = list(total_data.商品小類.unique())\ngroups_small_category= total_data.groupby(['月份','商品小類'])\nresults = {} \nfor i,j in groups_small_category: \n money = int(j.金額.sum())\n if i[0] in results.keys():\n results[i[0]][i[1]] = money \n else:\n results[i[0]] = {} \n for cate in category_names:\n results[i[0]][cate] = 0\n results[i[0]]['口紅'] = money\n\nresults= {key_data:list(values_data.values()) for key_data,values_data in results.items()}\ndef survey(results, category_names):\n labels = list(results.keys())\n data = np.array(list(results.values()))\n\n data_cum = data.cumsum(axis=1)\n category_colors = plt.get_cmap('RdYlGn')(\n np.linspace(0.15, 0.85, data.shape[1]))\n\n fig, ax = plt.subplots(figsize=(25,8))\n ax.invert_yaxis()\n ax.xaxis.set_visible(False)\n ax.set_xlim(0, np.sum(data, axis=1).max())\n\n for i, (colname, color) in enumerate(zip(category_names, category_colors)):\n widths = data[:, i]\n starts = data_cum[:, i] - widths\n ax.barh(labels, widths, left=starts, height=0.5,\n label=colname, color=color)\n xcenters = starts + widths / 2\n\n# r, g, b, _ = color\n# text_color = 'white' if r * g * b < 0.5 else 'darkgrey'\n# for y, (x, c) in enumerate(zip(xcenters, widths)):\n# ax.text(x, y, str(int(c)), ha='center', va='center')\n ax.legend(ncol=len(category_names), bbox_to_anchor=(0, 1),\n loc='lower left', fontsize='small')\n\n return fig, ax\nsurvey(results, category_names)\n\nplt.show()","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/e4/e4c02d9c5fb6e5f5eb6a54931e27cfd4.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖表說明:眼霜、爽膚水、面膜:4,5,6,7,8月份需求量最大;粉底、防曬霜、隔離霜、睫毛膏、蜜粉1,2,3月份需求量最大。","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"data_user_buy=total_data.groupby('客戶編碼')['訂單編碼'].count()\ndata_user_buy\nplt.figure(figsize=(10,4),dpi=80)\nplt.hist(data_user_buy,color='#FFEC8B')\n\nplt.title('用戶購買次數分佈',fontsize=16)\nplt.xlabel('購買次數')\nplt.ylabel('用戶數')\nplt.show()","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/a3/a3a4e6e28c1c7a87ed4de2a02f94ccf5.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖表說明:大部分用戶購買次數在10次-35次之間,極少部分用戶購買次數80次以上","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"date_rebuy=total_data.groupby('客戶編碼')['訂單日期'].apply(lambda x:len(x.unique())).rename('rebuy_count')\ndate_rebuy\nprint('復購率:',round(date_rebuy[date_rebuy>=2].count()/date_rebuy.count(),4))","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/22/22dc711e1e732d68f34ad9eda40fcd79.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"total_data['時間標籤'] = total_data['訂單日期'].astype(str).str[:7]\ntotal_data = total_data[total_data['時間標籤']!='2050-06']\ntotal_data['時間標籤'].value_counts().sort_index()\ntotal_data = total_data.sort_values(by='時間標籤')\nmonth_lst = total_data['時間標籤'].unique()\nfinal=pd.DataFrame()\nfinal\n#引入時間標籤\nfor i in range(len(month_lst)-1):\n #構造和月份一樣長的列表,方便後續格式統一\n count = [0] * len(month_lst)\n #篩選出當月訂單,並按客戶暱稱分組\n target_month = total_data.loc[total_data['時間標籤']==month_lst[i],:]\n target_users = target_month.groupby('客戶編碼')['金額'].sum().reset_index()\n\n #如果是第一個月份,則跳過(因爲不需要和歷史數據驗證是否爲新增客戶)\n if i==0:\n new_target_users = target_month.groupby('客戶編碼')['金額'].sum().reset_index()\n else:\n #如果不是,找到之前的歷史訂單\n history = total_data.loc[total_data['時間標籤'].isin(month_lst[:i]),:]\n #篩選出未在歷史訂單出現過的新增客戶\n new_target_users = target_users.loc[target_users['客戶編碼'].isin(history['客戶編碼']) == False,:]\n\n #當月新增客戶數放在第一個值中\n count[0] = len(new_target_users)\n\n #以月爲單位,循環遍歷,計算留存情況\n for j,ct in zip(range(i + 1,len(month_lst)),range(1,len(month_lst))):\n #下一個月的訂單\n next_month = total_data.loc[total_data['時間標籤'] == month_lst[j],:]\n next_users = next_month.groupby('客戶編碼')['金額'].sum().reset_index()\n #計算在該月仍然留存的客戶數量\n isin = new_target_users['客戶編碼'].isin(next_users['客戶編碼']).sum()\n count[ct] = isin\n\n #格式轉置\n result = pd.DataFrame({month_lst[i]:count}).T\n\n #合併\n final = pd.concat([final,result])\n\nfinal.columns = ['當月新增','+1月','+2月','+3月','+4月','+5月','+6月','+7月','+8月']\nresult = final.divide(final['當月新增'],axis=0).iloc[:]\nresult['當月新增'] = final['當月新增']\nresult.round(2)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/a2/a24e956ce7898b1a78a6b23e93f08d2b.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖表說明:由新增用戶情況看,新用戶逐月明顯減少;留存率在1月-5月平均在50%,6月-8月留存率上升明顯。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"結論與建議","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1、從銷售額趨勢來看,整體是上升趨勢,但是從8月份銷售額突然下降,可能因爲到淡季,需進一步確認原因;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2、商品銷售額,用戶對護膚品具有強烈的需求,尤其是面膜,爽膚水、面霜、眼霜。較低需求的是蜜粉。可以把高需求產品,組合成禮盒等套裝活動;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"3、商品銷售建議:眼霜、爽膚水、面膜:4,5,6,7,8月需求最大;粉底、防曬霜、隔離霜、睫毛膏、蜜粉1,2,3月需求最大。以上說明用戶購買特定產品具有周期性;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"4、從地域來看,東部地區是消費的主力軍,其中江蘇省、廣東省、浙江省的銷售額最大。可以增大市場投放量;也可以考慮在該地區建倉,節省物流等成本;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"5、用戶:重點維護購買次數在10次-35次之間的用戶羣體;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"6、留存率在99%,證明用戶對產品有一定的依賴性;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"7、從同期羣分析來看,新用戶明顯減少,應考慮拉新,增加平臺新用戶(主播帶貨等);","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"原創不易,碼字不易。","attrs":{}},{"type":"text","text":" 覺得這篇文章對你有點用的話,麻煩你爲本文","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"點個贊","attrs":{}},{"type":"text","text":",","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"留言","attrs":{}},{"type":"text","text":" 或 ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"轉發 ","attrs":{}},{"type":"text","text":"一下,因爲這將是我","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"輸出更多優質文章的動力","attrs":{}},{"type":"text","text":",感謝!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同時,也歡迎關注我的","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"個人原創公衆號:傑哥的IT之旅","attrs":{}},{"type":"text","text":"。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/01/019b65e5ec6661e8bbcaec704494797d.jpeg","alt":null,"title":"","style":[{"key":"width","value":"100%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章