{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"#Load all libraries\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nfrom matplotlib import pyplot as plt\nimport matplotlib.dates as mdates\nimport matplotlib.ticker as ticker\nimport plotly.graph_objects as go\nimport datetime as dt\nimport matplotlib.image as mpimg","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-05-27T07:25:41.101244Z","iopub.execute_input":"2022-05-27T07:25:41.101720Z","iopub.status.idle":"2022-05-27T07:25:41.775804Z","shell.execute_reply.started":"2022-05-27T07:25:41.101687Z","shell.execute_reply":"2022-05-27T07:25:41.774435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"EDA on Datasets","metadata":{}},{"cell_type":"code","source":"#Load all the datasets\narticles = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/articles.csv\")\ncustomers = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/customers.csv\")\ntransactions = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:25:41.777712Z","iopub.execute_input":"2022-05-27T07:25:41.778611Z","iopub.status.idle":"2022-05-27T07:27:01.851792Z","shell.execute_reply.started":"2022-05-27T07:25:41.778567Z","shell.execute_reply":"2022-05-27T07:27:01.850535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Let's find out the shapes of all three dataframes\nshape=pd.DataFrame({\"Total Rows\":[articles.shape[0],customers.shape[0],transactions.shape[0]],\n                    \"Total Columns\":[articles.shape[1],customers.shape[1],transactions.shape[1]]},index=['articles','customers','transactions'])\nshape","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:01.853001Z","iopub.execute_input":"2022-05-27T07:27:01.853515Z","iopub.status.idle":"2022-05-27T07:27:01.877388Z","shell.execute_reply.started":"2022-05-27T07:27:01.853475Z","shell.execute_reply":"2022-05-27T07:27:01.876062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:01.880426Z","iopub.execute_input":"2022-05-27T07:27:01.880998Z","iopub.status.idle":"2022-05-27T07:27:01.895080Z","shell.execute_reply.started":"2022-05-27T07:27:01.880951Z","shell.execute_reply":"2022-05-27T07:27:01.893911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:01.896540Z","iopub.execute_input":"2022-05-27T07:27:01.897400Z","iopub.status.idle":"2022-05-27T07:27:01.914876Z","shell.execute_reply.started":"2022-05-27T07:27:01.897365Z","shell.execute_reply":"2022-05-27T07:27:01.913803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n = len(pd.unique(transactions['customer_id'])) \nm = len(pd.unique(customers['customer_id'])) ","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:01.916536Z","iopub.execute_input":"2022-05-27T07:27:01.917539Z","iopub.status.idle":"2022-05-27T07:27:11.010846Z","shell.execute_reply.started":"2022-05-27T07:27:01.917500Z","shell.execute_reply":"2022-05-27T07:27:11.009744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(n)\nprint(m)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:11.012137Z","iopub.execute_input":"2022-05-27T07:27:11.012492Z","iopub.status.idle":"2022-05-27T07:27:11.018343Z","shell.execute_reply.started":"2022-05-27T07:27:11.012461Z","shell.execute_reply":"2022-05-27T07:27:11.017359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"length=len(set(transactions.customer_id.values.tolist()))/customers.shape[0]\nnpur=100-(length*100)\nprint(\"Total No of customers:\",m)\nprint(\"No of customers who made at least one transaction:\",n)\nprint(\"% of customers who made a at least one transaction : \",length*100)\nprint(\"Number of customers who did not make a purchase : \",(customers.shape[0] - len(set(transactions.customer_id.values.tolist()))))\nprint(\"% of customers who did not make a purchase : \",npur)\nprint(\"It seems that not all customers made a purchase, there is around 1% with no purchase history.\")","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:11.019543Z","iopub.execute_input":"2022-05-27T07:27:11.019926Z","iopub.status.idle":"2022-05-27T07:27:19.800288Z","shell.execute_reply.started":"2022-05-27T07:27:11.019894Z","shell.execute_reply":"2022-05-27T07:27:19.799247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:19.801617Z","iopub.execute_input":"2022-05-27T07:27:19.801979Z","iopub.status.idle":"2022-05-27T07:27:19.834948Z","shell.execute_reply.started":"2022-05-27T07:27:19.801949Z","shell.execute_reply":"2022-05-27T07:27:19.833787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#check null values in transaction dataset\ntransactions.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:19.838087Z","iopub.execute_input":"2022-05-27T07:27:19.838521Z","iopub.status.idle":"2022-05-27T07:27:26.816132Z","shell.execute_reply.started":"2022-05-27T07:27:19.838485Z","shell.execute_reply":"2022-05-27T07:27:26.814995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Articles Sold","metadata":{}},{"cell_type":"code","source":"year=transactions.groupby('t_dat').count()[['article_id']]\nyearwise1=year.reset_index()\n#yearwise1.head()\nprint (transactions.t_dat.min())\nprint (transactions.t_dat.max())","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:26.817754Z","iopub.execute_input":"2022-05-27T07:27:26.818297Z","iopub.status.idle":"2022-05-27T07:27:43.806085Z","shell.execute_reply.started":"2022-05-27T07:27:26.818235Z","shell.execute_reply":"2022-05-27T07:27:43.804912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions[transactions['t_dat']=='2018-09-20']","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:43.807848Z","iopub.execute_input":"2022-05-27T07:27:43.808397Z","iopub.status.idle":"2022-05-27T07:27:49.046840Z","shell.execute_reply.started":"2022-05-27T07:27:43.808306Z","shell.execute_reply":"2022-05-27T07:27:49.045764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"year","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:49.048474Z","iopub.execute_input":"2022-05-27T07:27:49.048992Z","iopub.status.idle":"2022-05-27T07:27:49.062204Z","shell.execute_reply.started":"2022-05-27T07:27:49.048940Z","shell.execute_reply":"2022-05-27T07:27:49.060725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"yearasecact = yearwise1.sort_values(['article_id'], ascending=False).head(5)\nyearasecact","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:49.064189Z","iopub.execute_input":"2022-05-27T07:27:49.064598Z","iopub.status.idle":"2022-05-27T07:27:49.085654Z","shell.execute_reply.started":"2022-05-27T07:27:49.064565Z","shell.execute_reply":"2022-05-27T07:27:49.084399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"yearwise1['t_dat'] = pd.to_datetime(yearwise1['t_dat'], format='%Y/%m/%d')\n\nsns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,12)\n\nax.plot('t_dat', 'article_id', data=yearwise1, color='#6a0573', linewidth=2)\n\nplt.tight_layout()\nax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))\nax.xaxis.set_major_locator(ticker.MultipleLocator(100))\nplt.xticks(rotation=90)\nttl = ax.set_title('Articles Sold from 2018-09-20 to 2020-09-22', fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\n\nx_line_annotation = dt.datetime(2019,9,22)\n\nax.annotate('Maximum Articles Sold',\n            xy=(x_line_annotation, 198522),\n            xycoords='data',\n            xytext=(55, 0), textcoords='offset points',\n            size=15, va=\"center\",\n            color='#3e0542',\n            bbox=dict(boxstyle=\"round\",facecolor='#f7daf7', edgecolor='#3e0542'),\n            arrowprops=dict(arrowstyle=\"wedge,tail_width=1.\",\n                            facecolor='#f7daf7', \n                            edgecolor='#3e0542',\n                            relpos=(0.1, 0.4)))\n\n\nttl.set_position([.5, 1.02])\nax.set_ylabel('No of Articles', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\nfor label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    label.set_fontsize(14)\n# Adjust subplots so that the title and labels would fit\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:49.087842Z","iopub.execute_input":"2022-05-27T07:27:49.088701Z","iopub.status.idle":"2022-05-27T07:27:49.712228Z","shell.execute_reply.started":"2022-05-27T07:27:49.088658Z","shell.execute_reply":"2022-05-27T07:27:49.711017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"there are distinct spikes in 3 years.Maximum articles 198,622 are sold on the date 2019-09-28 which breaks all the records in 3 years.where as second maximum 162,799 articles are sold on date 2020-04-11 and third maximum 160,875 articles are sold on date 2019-11-29.","metadata":{}},{"cell_type":"markdown","source":"Transaction Amount","metadata":{}},{"cell_type":"code","source":"yearp=transactions.groupby('t_dat').sum()[['price']]\nyearwise1p=yearp.reset_index()\n#yearwise1p.head()\nprint (yearwise1p.price.max())","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:49.713463Z","iopub.execute_input":"2022-05-27T07:27:49.713945Z","iopub.status.idle":"2022-05-27T07:27:54.250322Z","shell.execute_reply.started":"2022-05-27T07:27:49.713906Z","shell.execute_reply":"2022-05-27T07:27:54.249101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"yearp","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:54.252063Z","iopub.execute_input":"2022-05-27T07:27:54.252624Z","iopub.status.idle":"2022-05-27T07:27:54.266385Z","shell.execute_reply.started":"2022-05-27T07:27:54.252587Z","shell.execute_reply":"2022-05-27T07:27:54.264959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"yearasec = yearwise1p.sort_values(['price'], ascending=False).head(5)\nyearasec","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:54.268166Z","iopub.execute_input":"2022-05-27T07:27:54.268753Z","iopub.status.idle":"2022-05-27T07:27:54.291330Z","shell.execute_reply.started":"2022-05-27T07:27:54.268701Z","shell.execute_reply":"2022-05-27T07:27:54.289775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nyearwise1p['t_dat'] = pd.to_datetime(yearwise1p['t_dat'], format='%Y/%m/%d')\n\nsns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,12)\n\nax.plot('t_dat', 'price', data=yearwise1p, color='#6a0573', linewidth=2)\n\nplt.tight_layout()\nax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))\nax.xaxis.set_major_locator(ticker.MultipleLocator(100))\nplt.xticks(rotation=90)\nttl = ax.set_title('Transaction amount from 2018-09-20 to 2020-09-22', fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\nx_line_annotation = dt.datetime(2019,9,22)\n\nax.annotate('Maximum Amount Transaction',\n            xy=(x_line_annotation,6161),\n            xycoords='data',\n            xytext=(55, 0), textcoords='offset points',\n            size=15, va=\"center\",\n            color='#3e0542',\n            bbox=dict(boxstyle=\"round\",facecolor='#f7daf7', edgecolor='#3e0542'),\n            arrowprops=dict(arrowstyle=\"wedge,tail_width=1.\",\n                            facecolor='#f7daf7', \n                            edgecolor='#3e0542',\n                            relpos=(0.1, 0.4)))\n\nttl.set_position([.5, 1.02])\nax.set_ylabel('Amount', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\nfor label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    label.set_fontsize(14)\n# Adjust subplots so that the title and labels would fit\n\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:54.293068Z","iopub.execute_input":"2022-05-27T07:27:54.294525Z","iopub.status.idle":"2022-05-27T07:27:54.818947Z","shell.execute_reply.started":"2022-05-27T07:27:54.294468Z","shell.execute_reply":"2022-05-27T07:27:54.818192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"maximum transaction amount on date 2019-09-28 is 6,161.where as second maximum transaction is 4,444 on date 2019-11-29 which shows that the transacation amount is 25% decreases in 2019-11-29.","metadata":{}},{"cell_type":"markdown","source":"Top Ten Customers","metadata":{}},{"cell_type":"code","source":"check=transactions.groupby('customer_id').count()[['article_id']].sort_values('article_id', ascending=False)\nnewcheck=check.head(10)\nnewcheck1=newcheck.reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:27:54.820121Z","iopub.execute_input":"2022-05-27T07:27:54.821007Z","iopub.status.idle":"2022-05-27T07:28:14.066190Z","shell.execute_reply.started":"2022-05-27T07:27:54.820966Z","shell.execute_reply":"2022-05-27T07:28:14.065152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:28:14.067658Z","iopub.execute_input":"2022-05-27T07:28:14.068048Z","iopub.status.idle":"2022-05-27T07:28:14.079029Z","shell.execute_reply.started":"2022-05-27T07:28:14.068017Z","shell.execute_reply":"2022-05-27T07:28:14.077884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = go.Figure(data=[go.Table(\n    header=dict(values = [['<b>Customer ID</b><br>Top 10'],\n                ['<b>Item Count</b>']],\n                fill_color='#d6b6d5',\n                font_color=\"#3e0542\",\n                align='left'),\n    cells=dict(values=[newcheck1.customer_id, newcheck1.article_id],\n               fill_color='#faf0fa',\n               align='left'))\n])\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:28:14.080354Z","iopub.execute_input":"2022-05-27T07:28:14.081299Z","iopub.status.idle":"2022-05-27T07:28:14.303520Z","shell.execute_reply.started":"2022-05-27T07:28:14.081258Z","shell.execute_reply":"2022-05-27T07:28:14.302668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"top 10 customers are those which bought article more than 1,000 in the last three years","metadata":{}},{"cell_type":"markdown","source":"Articles Sold by Age Distribution","metadata":{}},{"cell_type":"code","source":"custfin= pd.DataFrame(customers, columns = ['customer_id','age'])","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:28:14.304730Z","iopub.execute_input":"2022-05-27T07:28:14.305548Z","iopub.status.idle":"2022-05-27T07:28:14.340743Z","shell.execute_reply.started":"2022-05-27T07:28:14.305508Z","shell.execute_reply":"2022-05-27T07:28:14.339945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"total_tran = pd.merge(custfin,transactions, how='right', on='customer_id')","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:28:14.342074Z","iopub.execute_input":"2022-05-27T07:28:14.342759Z","iopub.status.idle":"2022-05-27T07:28:35.309005Z","shell.execute_reply.started":"2022-05-27T07:28:14.342712Z","shell.execute_reply":"2022-05-27T07:28:35.307865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"total_tran[\"age\"].fillna(value=0,inplace=True)\ntotal_tran[\"age\"]=total_tran[\"age\"].apply(int)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:28:35.310422Z","iopub.execute_input":"2022-05-27T07:28:35.310993Z","iopub.status.idle":"2022-05-27T07:28:55.634646Z","shell.execute_reply.started":"2022-05-27T07:28:35.310948Z","shell.execute_reply":"2022-05-27T07:28:55.633554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,12)\nax = sns.histplot(data=total_tran, x='age', bins=50,color='#6a0573')\n\nax.annotate('Age \\n not given',\n            xy=(0,216100),\n            xycoords='data',\n            xytext=(55, 0), textcoords='offset points',\n            size=10, va=\"center\",\n            color='#3e0542',\n            bbox=dict(boxstyle=\"round\",facecolor='#f7daf7', edgecolor='#3e0542'),\n            arrowprops=dict(arrowstyle=\"wedge,tail_width=1.\",\n                            facecolor='#f7daf7', \n                            edgecolor='#3e0542',\n                            relpos=(0.1, 0.4)))\n\nax.axvline(x=20, linestyle='dashed', alpha=0.5,color='#3e0542')\nax.axvline(x=38, linestyle='dashed', alpha=0.5,color='#3e0542')\nax.text(x=20.5, y=3161000, s='Maximum buyers range', alpha=0.7, color='#3e0542',fontweight = 'bold')\nttl.set_position([.5, 1.02])\nax.set_ylabel('No of Articles', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nax.set_xlabel('Age', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\nfor label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    label.set_fontsize(14)\nttl = ax.set_title('Articles sold by Age', fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\n\n# Adjust subplots so that the title and labels would fit\n\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:28:55.636282Z","iopub.execute_input":"2022-05-27T07:28:55.636910Z","iopub.status.idle":"2022-05-27T07:29:04.815647Z","shell.execute_reply.started":"2022-05-27T07:28:55.636873Z","shell.execute_reply":"2022-05-27T07:29:04.814322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Articles Sold by Sales Channel","metadata":{}},{"cell_type":"code","source":"datanew= pd.DataFrame(total_tran, columns = ['price','t_dat','sales_channel_id','article_id'])\ndf = datanew.groupby([\"t_dat\", \"sales_channel_id\"])[\"article_id\"].count().reset_index()\nprint (df.article_id.max())\nprint (df.article_id.min())","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:04.817266Z","iopub.execute_input":"2022-05-27T07:29:04.817742Z","iopub.status.idle":"2022-05-27T07:29:14.149805Z","shell.execute_reply.started":"2022-05-27T07:29:04.817698Z","shell.execute_reply":"2022-05-27T07:29:14.148568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfasec = df.sort_values(['article_id'], ascending=True).head(5)\ndfasec","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:14.155779Z","iopub.execute_input":"2022-05-27T07:29:14.156173Z","iopub.status.idle":"2022-05-27T07:29:14.167840Z","shell.execute_reply.started":"2022-05-27T07:29:14.156142Z","shell.execute_reply":"2022-05-27T07:29:14.166594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\ndf['t_dat'] = pd.to_datetime(df['t_dat'], format='%Y/%m/%d')\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:14.169991Z","iopub.execute_input":"2022-05-27T07:29:14.170392Z","iopub.status.idle":"2022-05-27T07:29:14.181421Z","shell.execute_reply.started":"2022-05-27T07:29:14.170358Z","shell.execute_reply":"2022-05-27T07:29:14.180438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xmin = df[\"t_dat\"].min()\nxmax = df[\"t_dat\"].max()\n\nymin = df[\"article_id\"].min() - 1000\nymax = df[\"article_id\"].max() + 1000","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:14.182663Z","iopub.execute_input":"2022-05-27T07:29:14.183873Z","iopub.status.idle":"2022-05-27T07:29:14.198156Z","shell.execute_reply.started":"2022-05-27T07:29:14.183648Z","shell.execute_reply":"2022-05-27T07:29:14.197315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#df['t_dat'] = pd.to_datetime(df['t_dat'], format='%Y/%m/%d')\nsns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,12)\n\nax.plot(df.loc[df[\"sales_channel_id\"]==1, \"t_dat\"], df.loc[df[\"sales_channel_id\"]==1, \"article_id\"], label=\"Sales Channel 1\", color=\"Darkblue\")\nax.plot(df.loc[df[\"sales_channel_id\"]==2, \"t_dat\"], df.loc[df[\"sales_channel_id\"]==2, \"article_id\"], label=\"Sales Channel 2\", color=\"Magenta\")\nax.annotate('Maximum Items Sold',\n            xy=(x_line_annotation,167500),\n            xycoords='data',\n            xytext=(55, 0), textcoords='offset points',\n            size=15, va=\"center\",\n            color='#3e0542',\n            bbox=dict(boxstyle=\"round\",facecolor='#f7daf7', edgecolor='#3e0542'),\n            arrowprops=dict(arrowstyle=\"wedge,tail_width=1.\",\n                            facecolor='#f7daf7', \n                            edgecolor='#3e0542',\n                            relpos=(0.1, 0.4)))\nax.set_ylim(ymin, ymax)\nax.set_xlim(xmin, xmax)\n\nax.fill_betweenx([ymin,ymax],18343, 18384, color=\"gray\", alpha=0.3)\n\nprops = dict(boxstyle='round',facecolor='#f7daf7', edgecolor='#3e0542', alpha=0.5)\nax.annotate(\"Missing transaction\\n period\", (18342, 17000), (18270, 67000), \\\n    arrowprops={\"arrowstyle\": \"->\", \"color\":\"C1\"},\n    color='#3e0542',\n    bbox=props,\n    fontproperties='italic'\n    );\n\n\nax.set_ylabel('No of Articles', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\n\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\nplt.xticks(rotation=90)\nlegend=plt.legend(title=\"Sales Channel ID\",labelcolor='linecolor')\nplt.setp(legend.get_title(), color='#3e0542',fontweight = 'bold')\nfor label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    label.set_fontsize(14)\nplt.title(f\"Articles sold by Sales Channel\",fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:14.199569Z","iopub.execute_input":"2022-05-27T07:29:14.200460Z","iopub.status.idle":"2022-05-27T07:29:14.820802Z","shell.execute_reply.started":"2022-05-27T07:29:14.200390Z","shell.execute_reply":"2022-05-27T07:29:14.820023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Transaction Amount by Sales Channel","metadata":{}},{"cell_type":"code","source":"dfp = datanew.groupby([\"t_dat\", \"sales_channel_id\"])[\"price\"].sum().reset_index()\nprint (dfp.price.max())","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:14.822330Z","iopub.execute_input":"2022-05-27T07:29:14.822860Z","iopub.status.idle":"2022-05-27T07:29:19.470787Z","shell.execute_reply.started":"2022-05-27T07:29:14.822815Z","shell.execute_reply":"2022-05-27T07:29:19.469253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfp.sort_values(by=['price'], ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:19.472522Z","iopub.execute_input":"2022-05-27T07:29:19.473237Z","iopub.status.idle":"2022-05-27T07:29:19.494124Z","shell.execute_reply.started":"2022-05-27T07:29:19.473188Z","shell.execute_reply":"2022-05-27T07:29:19.493049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfp['t_dat'] = pd.to_datetime(dfp['t_dat'], format='%Y/%m/%d')\nsns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,12)\n\nax.plot(dfp.loc[dfp[\"sales_channel_id\"]==1, \"t_dat\"], dfp.loc[dfp[\"sales_channel_id\"]==1, \"price\"], label=\"Sales Channel 1\", color=\"Darkblue\")\nax.plot(dfp.loc[dfp[\"sales_channel_id\"]==2, \"t_dat\"], dfp.loc[dfp[\"sales_channel_id\"]==2, \"price\"], label=\"Sales Channel 2\", color=\"Magenta\")\nax.annotate('Maximum amount',\n            xy=(x_line_annotation,5365),\n            xycoords='data',\n            xytext=(55, 0), textcoords='offset points',\n            size=15, va=\"center\",\n            color='#3e0542',\n            bbox=dict(boxstyle=\"round\",facecolor='#f7daf7', edgecolor='#3e0542'),\n            arrowprops=dict(arrowstyle=\"wedge,tail_width=1.\",\n                            facecolor='#f7daf7', \n                            edgecolor='#3e0542',\n                            relpos=(0.1, 0.4)))\n\n\nax.set_ylabel('Amount', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\n\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\nplt.xticks(rotation=90)\nlegend=plt.legend(title=\"Sales Channel ID\",labelcolor='linecolor')\nplt.setp(legend.get_title(), color='#3e0542',fontweight = 'bold')\nfor label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    label.set_fontsize(14)\nplt.title(f\"Transactions Amount by Sales Channel\",fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:19.496048Z","iopub.execute_input":"2022-05-27T07:29:19.496857Z","iopub.status.idle":"2022-05-27T07:29:20.053457Z","shell.execute_reply.started":"2022-05-27T07:29:19.496789Z","shell.execute_reply":"2022-05-27T07:29:20.052488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Maximum transaction amount on the date 2019-09-28 are also hit by sales channel 2.Transactions amount are missing for sales channel 1 for few months","metadata":{}},{"cell_type":"markdown","source":"Articles sold by Product Group","metadata":{}},{"cell_type":"code","source":"datanew1= pd.DataFrame(transactions, columns = ['article_id','price'])\nartdept=pd.DataFrame(articles, columns = ['article_id','colour_group_name','department_name','index_group_name','product_group_name'])","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:20.054845Z","iopub.execute_input":"2022-05-27T07:29:20.055933Z","iopub.status.idle":"2022-05-27T07:29:20.279812Z","shell.execute_reply.started":"2022-05-27T07:29:20.055884Z","shell.execute_reply":"2022-05-27T07:29:20.278916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\ndepartment = pd.merge(artdept,datanew1, how='right', on='article_id')\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:20.280947Z","iopub.execute_input":"2022-05-27T07:29:20.281871Z","iopub.status.idle":"2022-05-27T07:29:29.048642Z","shell.execute_reply.started":"2022-05-27T07:29:20.281827Z","shell.execute_reply":"2022-05-27T07:29:29.047548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\ndepartmentc=department.groupby(['product_group_name','index_group_name'])['article_id'].count().reset_index()\ndepartmentc1 = departmentc.sort_values(['article_id'], ascending=False)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:29.050017Z","iopub.execute_input":"2022-05-27T07:29:29.050352Z","iopub.status.idle":"2022-05-27T07:29:37.286420Z","shell.execute_reply.started":"2022-05-27T07:29:29.050324Z","shell.execute_reply":"2022-05-27T07:29:37.285607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,16)\nflatui = [\"#9b59b6\", \"#3498db\", \"#e74c3c\", \"#34495e\", \"#2ecc71\"]\n\nsns.barplot(data=departmentc1,y=\"product_group_name\", x=\"article_id\",hue=\"index_group_name\",palette=flatui,alpha = 0.6, edgecolor = 'k', linewidth = 2)\n\nplt.tight_layout()\n\n\nttl = ax.set_title('Articles Sold by Product Group', fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\n\n\nttl.set_position([.5, 1.02])\nax.set_ylabel('Product Group', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nax.set_xlabel('No of Articles', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\nlegend=plt.legend(title=\"Index Group Name\")\nplt.setp(legend.get_title(),fontweight = 'bold')\nfor label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    label.set_fontsize(14)\n# Adjust subplots so that the title and labels would fit\n\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:37.287474Z","iopub.execute_input":"2022-05-27T07:29:37.288144Z","iopub.status.idle":"2022-05-27T07:29:38.592195Z","shell.execute_reply.started":"2022-05-27T07:29:37.288110Z","shell.execute_reply":"2022-05-27T07:29:38.591175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Ladieswear index group are more dominant for top 5 product group","metadata":{}},{"cell_type":"markdown","source":"Articles Sold by Department","metadata":{}},{"cell_type":"code","source":"\n\ndepartmentp=department.groupby(['department_name'])['article_id'].count().reset_index()\ndepartmentp1 = departmentp.sort_values(['article_id'], ascending=False).head(50)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:38.593768Z","iopub.execute_input":"2022-05-27T07:29:38.594446Z","iopub.status.idle":"2022-05-27T07:29:42.350352Z","shell.execute_reply.started":"2022-05-27T07:29:38.594397Z","shell.execute_reply":"2022-05-27T07:29:42.349122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,16)\nsns.barplot(data=departmentp1,y=\"department_name\", x=\"article_id\",palette=\"flare\",alpha = 0.6, edgecolor = 'k', linewidth = 2)\nplt.tight_layout()\nttl = ax.set_title('Articles Sold by Department', fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\nttl.set_position([.5, 1.02])\nax.set_ylabel('Department Name', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nax.set_xlabel('No of Articles', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\n\nfor label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    label.set_fontsize(14)\n# Adjust subplots so that the title and labels would fit\n\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:42.351792Z","iopub.execute_input":"2022-05-27T07:29:42.352756Z","iopub.status.idle":"2022-05-27T07:29:43.681930Z","shell.execute_reply.started":"2022-05-27T07:29:42.352698Z","shell.execute_reply":"2022-05-27T07:29:43.680895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"articles swimwear,trouser and blouse are the most dominant","metadata":{}},{"cell_type":"markdown","source":"Articles Sold by Colour","metadata":{}},{"cell_type":"code","source":"art1=pd.DataFrame(articles, columns = ['article_id','colour_group_name','garment_group_name','section_name','product_type_name'])","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:43.683373Z","iopub.execute_input":"2022-05-27T07:29:43.683737Z","iopub.status.idle":"2022-05-27T07:29:43.692176Z","shell.execute_reply.started":"2022-05-27T07:29:43.683705Z","shell.execute_reply":"2022-05-27T07:29:43.691368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dep1 = pd.merge(art1,datanew1, how='right', on='article_id')","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:43.693266Z","iopub.execute_input":"2022-05-27T07:29:43.694093Z","iopub.status.idle":"2022-05-27T07:29:51.942194Z","shell.execute_reply.started":"2022-05-27T07:29:43.694056Z","shell.execute_reply":"2022-05-27T07:29:51.941456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\ndep2=dep1.groupby(['colour_group_name'])['article_id'].count().reset_index()\ndepa = dep2.sort_values(['article_id'], ascending=False)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:51.943478Z","iopub.execute_input":"2022-05-27T07:29:51.944316Z","iopub.status.idle":"2022-05-27T07:29:55.597432Z","shell.execute_reply.started":"2022-05-27T07:29:51.944280Z","shell.execute_reply":"2022-05-27T07:29:55.596472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,16)\nsns.barplot(data=depa,y=\"colour_group_name\", x=\"article_id\",palette=\"flare\",alpha = 0.6, edgecolor = 'k', linewidth = 2)\nplt.tight_layout()\nttl = ax.set_title('Articles Sold by Colour', fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\nttl.set_position([.5, 1.02])\nax.set_ylabel('Colour Group', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nax.set_xlabel('No of Articles', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\n\nfor label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    label.set_fontsize(14)\n# Adjust subplots so that the title and labels would fit\n\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:55.599018Z","iopub.execute_input":"2022-05-27T07:29:55.599665Z","iopub.status.idle":"2022-05-27T07:29:56.734648Z","shell.execute_reply.started":"2022-05-27T07:29:55.599625Z","shell.execute_reply":"2022-05-27T07:29:56.733481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n\nBlack color garments are highly demanded by the customers.\n","metadata":{}},{"cell_type":"markdown","source":"Articles Sold by Garment","metadata":{}},{"cell_type":"code","source":"dep3=dep1.groupby(['garment_group_name'])['article_id'].count().reset_index()\ndepa1 = dep3.sort_values(['article_id'], ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:29:56.736259Z","iopub.execute_input":"2022-05-27T07:29:56.737336Z","iopub.status.idle":"2022-05-27T07:30:00.457765Z","shell.execute_reply.started":"2022-05-27T07:29:56.737280Z","shell.execute_reply":"2022-05-27T07:30:00.456927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,16)\nplt.hlines(data=depa1,y=\"garment_group_name\",xmin=0,xmax=\"article_id\",alpha = 0.6, edgecolor = 'k', linewidth = 2,color='#3e0542')\nplt.plot(depa1['article_id'], depa1['garment_group_name'], \"D\")\n \nplt.tight_layout()\nttl = ax.set_title('Articles Sold by Garment', fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\nttl.set_position([.5, 1.02])\nax.set_ylabel('Grament Group', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nax.set_xlabel('No of Articles', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\n\nfor label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    label.set_fontsize(14)\n# Adjust subplots so that the title and labels would fit\n\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:30:00.459069Z","iopub.execute_input":"2022-05-27T07:30:00.459910Z","iopub.status.idle":"2022-05-27T07:30:00.830153Z","shell.execute_reply.started":"2022-05-27T07:30:00.459871Z","shell.execute_reply":"2022-05-27T07:30:00.828792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n\nJersey fancy and basic are the most frequent garment for customers.\n","metadata":{}},{"cell_type":"markdown","source":"Fashion News Frequency","metadata":{}},{"cell_type":"code","source":"cus=pd.DataFrame(customers, columns = ['club_member_status','fashion_news_frequency','customer_id'])\ntrans= pd.DataFrame(transactions, columns = ['customer_id'])","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:35:08.976759Z","iopub.execute_input":"2022-05-27T07:35:08.978427Z","iopub.status.idle":"2022-05-27T07:35:09.726805Z","shell.execute_reply.started":"2022-05-27T07:35:08.978364Z","shell.execute_reply":"2022-05-27T07:35:09.725388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"custran = pd.merge(cus,trans, how='right', on='customer_id')","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:35:14.535174Z","iopub.execute_input":"2022-05-27T07:35:14.536094Z","iopub.status.idle":"2022-05-27T07:35:32.589080Z","shell.execute_reply.started":"2022-05-27T07:35:14.536057Z","shell.execute_reply":"2022-05-27T07:35:32.587877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nct1=custran.groupby(['fashion_news_frequency'])['customer_id'].count().reset_index()\nct2 = ct1.sort_values(['customer_id'], ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:35:32.591331Z","iopub.execute_input":"2022-05-27T07:35:32.591752Z","iopub.status.idle":"2022-05-27T07:35:41.348284Z","shell.execute_reply.started":"2022-05-27T07:35:32.591715Z","shell.execute_reply":"2022-05-27T07:35:41.347110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,8)\nsns.barplot(data=ct2,x=\"fashion_news_frequency\", y=\"customer_id\",palette=\"flare\",alpha = 0.6, edgecolor = 'k', linewidth = 2)\nttl = ax.set_title('Fashion News Frequency', fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\nttl.set_position([.5, 1.02])\nax.set_ylabel('No of Cutomers', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nax.set_xlabel('Fashion News Frequency', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\n#for label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    #label.set_fontsize(14)\n# Adjust subplots so that the title and labels would fit\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:35:41.349761Z","iopub.execute_input":"2022-05-27T07:35:41.350386Z","iopub.status.idle":"2022-05-27T07:35:41.612041Z","shell.execute_reply.started":"2022-05-27T07:35:41.350344Z","shell.execute_reply":"2022-05-27T07:35:41.610623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"most of the customers do not recieve ang regular update about fashion news.","metadata":{}},{"cell_type":"markdown","source":"Club Member Status","metadata":{}},{"cell_type":"code","source":"cms1=custran.groupby(['club_member_status'])['customer_id'].count().reset_index()\ncms2 = cms1.sort_values(['customer_id'], ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:35:57.386534Z","iopub.execute_input":"2022-05-27T07:35:57.386997Z","iopub.status.idle":"2022-05-27T07:36:06.152790Z","shell.execute_reply.started":"2022-05-27T07:35:57.386961Z","shell.execute_reply":"2022-05-27T07:36:06.151572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(facecolor='#d6b6d5')\nfig.set_size_inches(18,8)\nsns.barplot(data=cms2,x=\"club_member_status\", y=\"customer_id\",palette=\"flare\",alpha = 0.6, edgecolor = 'k', linewidth = 2)\nttl = ax.set_title('Club Member Status', fontsize=18, pad=18, color=font_color, **csfont,fontweight = 'bold')\nttl.set_position([.5, 1.02])\nax.set_ylabel('No of Cutomers', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nax.set_xlabel('Club Member Status', color=font_color, fontsize=16, **hfont,fontweight = 'bold')\nplt.xticks(color=font_color, **hfont,fontweight = 'bold')\nplt.yticks(color=font_color, **hfont,fontweight = 'bold')\n#for label in (ax.get_xticklabels() + ax.get_yticklabels()):\n    #label.set_fontsize(14)\n# Adjust subplots so that the title and labels would fit\nplt.subplots_adjust(top=0.85, bottom=0.3, left=0.1, right=0.9)","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:36:06.154414Z","iopub.execute_input":"2022-05-27T07:36:06.154839Z","iopub.status.idle":"2022-05-27T07:36:06.399866Z","shell.execute_reply.started":"2022-05-27T07:36:06.154794Z","shell.execute_reply":"2022-05-27T07:36:06.398636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of the customers have an active membership status,only few are in pre-create status and no one with left club status.","metadata":{}},{"cell_type":"markdown","source":"Word Cloud for Description","metadata":{}},{"cell_type":"code","source":"\n\nprod_desc = articles[articles.detail_desc.notnull()].detail_desc.sample(5000).values\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:36:23.471599Z","iopub.execute_input":"2022-05-27T07:36:23.472234Z","iopub.status.idle":"2022-05-27T07:36:23.529788Z","shell.execute_reply.started":"2022-05-27T07:36:23.472169Z","shell.execute_reply":"2022-05-27T07:36:23.528965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from wordcloud import WordCloud, STOPWORDS\n\nstopwords = set(STOPWORDS) \nwordcloud = WordCloud(width = 800, \n                      height = 800,\n                      background_color ='white',\n                      min_font_size = 10,\n                      stopwords = stopwords,).generate(' '.join(prod_desc)) \n\n# plot the WordCloud image                        \nplt.figure(figsize = (8, 8), facecolor = '#d6b6d5') \nplt.imshow(wordcloud) \nplt.axis(\"off\") \nplt.tight_layout(pad = 0) \n\nplt.show() ","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:40:19.388133Z","iopub.execute_input":"2022-05-27T07:40:19.389457Z","iopub.status.idle":"2022-05-27T07:40:21.625529Z","shell.execute_reply.started":"2022-05-27T07:40:19.389385Z","shell.execute_reply":"2022-05-27T07:40:21.621551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Mean Price for Articles","metadata":{}},{"cell_type":"code","source":"\n\narticles_for_merge = articles[['article_id', 'product_group_name']]\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:40:43.621309Z","iopub.execute_input":"2022-05-27T07:40:43.621718Z","iopub.status.idle":"2022-05-27T07:40:43.632386Z","shell.execute_reply.started":"2022-05-27T07:40:43.621687Z","shell.execute_reply":"2022-05-27T07:40:43.631550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_for_merge = transactions[['article_id', 'price', 't_dat']].merge(articles_for_merge, on='article_id', how='left')","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:40:48.819254Z","iopub.execute_input":"2022-05-27T07:40:48.819767Z","iopub.status.idle":"2022-05-27T07:40:59.512626Z","shell.execute_reply.started":"2022-05-27T07:40:48.819731Z","shell.execute_reply":"2022-05-27T07:40:59.511584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\narticles_for_merge['t_dat'] = pd.to_datetime(articles_for_merge['t_dat'], format='%Y/%m/%d')\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:40:59.514497Z","iopub.execute_input":"2022-05-27T07:40:59.514943Z","iopub.status.idle":"2022-05-27T07:41:05.510261Z","shell.execute_reply.started":"2022-05-27T07:40:59.514908Z","shell.execute_reply":"2022-05-27T07:41:05.508810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"product_list = ['Shoes', 'Garment Full body', 'Bags', 'Garment Lower body', 'Underwear/nightwear','Accessories']\ncolors = ['cadetblue', 'orange', 'mediumspringgreen', 'tomato', 'lightseagreen','skyblue']\nk = 0\nsns.set(rc={'axes.facecolor':'#faf0fa'}) # graph facecolor\nfont_color = '#3e0542'\ncsfont = {'fontname':'Georgia'} # title font\nhfont = {'fontname':'Calibri'} # main font\nfig, ax = plt.subplots(3, 2, figsize=(20, 15),facecolor = '#d6b6d5')\n\nfor i in range(3):\n    for j in range(2):\n        try:\n            product = product_list[k]\n            articles_for_merge_product = articles_for_merge[articles_for_merge.product_group_name == product_list[k]]\n            series_mean = articles_for_merge_product[['t_dat', 'price']].groupby(pd.Grouper(key=\"t_dat\", freq='M')).mean().fillna(0)\n            series_std = articles_for_merge_product[['t_dat', 'price']].groupby(pd.Grouper(key=\"t_dat\", freq='M')).std().fillna(0)\n            ax[i, j].plot(series_mean, linewidth=4, color=colors[k])\n            ax[i, j].fill_between(series_mean.index, (series_mean.values-2*series_std.values).ravel(), \n                             (series_mean.values+2*series_std.values).ravel(), color=colors[k], alpha=.1)\n            ax[i, j].set_title(f'Mean {product_list[k]} price in time',fontsize=12, pad=18, color=font_color, **csfont,fontweight = 'bold')\n            ax[i, j].tick_params(axis='x', colors=font_color)\n            ax[i, j].tick_params(axis='y', colors=font_color)\n           \n            k += 1\n        except IndexError:\n            ax[i, j].set_visible(False)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:41:05.512911Z","iopub.execute_input":"2022-05-27T07:41:05.513540Z","iopub.status.idle":"2022-05-27T07:41:37.828525Z","shell.execute_reply.started":"2022-05-27T07:41:05.513488Z","shell.execute_reply":"2022-05-27T07:41:37.827485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Top 5 Articles with maximum price","metadata":{}},{"cell_type":"code","source":"\n\nmax_price_ids = transactions[transactions.t_dat==transactions.t_dat.max()].sort_values('price', ascending=False).iloc[:5][['article_id', 'price']]\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:41:39.179794Z","iopub.execute_input":"2022-05-27T07:41:39.180247Z","iopub.status.idle":"2022-05-27T07:41:48.686456Z","shell.execute_reply.started":"2022-05-27T07:41:39.180213Z","shell.execute_reply":"2022-05-27T07:41:48.685472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(1, 5, figsize=(20,10),facecolor = '#d6b6d5')\ni = 0\nfor _, data in max_price_ids.iterrows():\n    desc = articles[articles['article_id'] == data['article_id']]['detail_desc'].iloc[0]\n    desc_list = desc.split(' ')\n    for j, elem in enumerate(desc_list):\n        if j > 0 and j % 5 == 0:\n            desc_list[j] = desc_list[j] + '\\n'\n    desc = ' '.join(desc_list)\n    img = mpimg.imread(f'../input/h-and-m-personalized-fashion-recommendations/images/0{str(data.article_id)[:2]}/0{int(data.article_id)}.jpg')\n    ax[i].imshow(img)\n    ax[i].set_title(f'price: {data.price:.2f}',fontweight = 'bold')\n    ax[i].set_xticks([], [])\n    ax[i].set_yticks([], [])\n    ax[i].grid(False)\n    ax[i].set_xlabel(desc, fontsize=10,fontweight = 'bold')\n    i += 1\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:41:48.688374Z","iopub.execute_input":"2022-05-27T07:41:48.689535Z","iopub.status.idle":"2022-05-27T07:41:50.559951Z","shell.execute_reply.started":"2022-05-27T07:41:48.689480Z","shell.execute_reply":"2022-05-27T07:41:50.558723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Top 5 Articles with minimum price","metadata":{}},{"cell_type":"code","source":"min_price_ids = transactions[transactions.t_dat==transactions.t_dat.min()].sort_values('price', ascending=True).iloc[:5][['article_id', 'price']]","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:41:59.217691Z","iopub.execute_input":"2022-05-27T07:41:59.218301Z","iopub.status.idle":"2022-05-27T07:42:09.329484Z","shell.execute_reply.started":"2022-05-27T07:41:59.218252Z","shell.execute_reply":"2022-05-27T07:42:09.328617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(1, 5, figsize=(20,10),facecolor = '#d6b6d5')\ni = 0\nfor _, data in min_price_ids.iterrows():\n    desc = articles[articles['article_id'] == data['article_id']]['detail_desc'].iloc[0]\n    desc_list = desc.split(' ')\n    for j, elem in enumerate(desc_list):\n        if j > 0 and j % 4 == 0:\n            desc_list[j] = desc_list[j] + '\\n'\n    desc = ' '.join(desc_list)\n    img = mpimg.imread(f'../input/h-and-m-personalized-fashion-recommendations/images/0{str(data.article_id)[:2]}/0{int(data.article_id)}.jpg')\n    ax[i].imshow(img)\n    ax[i].set_title(f'price: {data.price:.4f}',fontweight = 'bold')\n    ax[i].set_xlabel(desc, fontsize=10,fontweight = 'bold')\n    ax[i].set_xticks([], [])\n    ax[i].set_yticks([], [])\n    ax[i].grid(False)\n    i += 1\nplt.axis('off')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-05-27T07:42:09.331363Z","iopub.execute_input":"2022-05-27T07:42:09.332069Z","iopub.status.idle":"2022-05-27T07:42:11.486998Z","shell.execute_reply.started":"2022-05-27T07:42:09.332018Z","shell.execute_reply":"2022-05-27T07:42:11.485752Z"},"trusted":true},"execution_count":null,"outputs":[]}]}