{"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":"markdown","source":"<a id=contents></a>\n# Contents\n\n[Articles](#articles)\n\n* [Unique values of each column](#unique_values_articles)\n* [prod_name](#prod_name)\n* [product_type_name](#product_type_name)\n* [product_group_name](#product_group_name)\n* [graphical_appearance_name](#graphical_appearance_name)\n* [colour_group_name](#colour_group_name)\n* [perceived_colour_value_name](#perceived_colour_value_name)\n* [perceived_colour_master_name](#perceived_colour_master_name)\n* [department_name](#department_name)\n* [index_name](#index_name)\n* [index_group_name](#index_group_name)\n* [section_name](#section_name)\n* [garment_group_name](#garment_group_name)\n\n[Customers](#customers)\n\n* [Unique values of each column](#unique_values_customers)\n* [FN](#FN)\n* [Active](#Active)\n* [club_member_status](#club_member_status)\n* [fashion_news_frequency](#fashion_news_frequency)\n* [age](#age)\n* [postal_code](#postal_code)\n\n[Transactions](#transactions)\n\n* [sales_channel_id](#sales_channel_id)\n* [price](#price)\n* [Price Distribution](#price_distribution)\n* [Top Selling Articles](#top_selling_articles)\n* [Top 10 Customers](#top_customers)\n* [Price Outliers](#price_outliers)\n* [Top Selling Product Group](#top_selling_product_group)\n* [Product Groups bought together](#product_groups_together)\n* [Product Types bought together](#product_types_together)\n* [Top group per postal code](#group_per_postal)\n* [Seasonal/all year round transactions](#seasonal)\n\n[Sales Distribution](#sales_distribution)\n","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nfrom matplotlib import pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-03-18T07:30:56.348647Z","iopub.execute_input":"2022-03-18T07:30:56.349499Z","iopub.status.idle":"2022-03-18T07:30:57.540985Z","shell.execute_reply.started":"2022-03-18T07:30:56.349378Z","shell.execute_reply":"2022-03-18T07:30:57.540231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv')\ncustomers = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')\ntransactions_train = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:41:35.831200Z","iopub.execute_input":"2022-03-18T08:41:35.831552Z","iopub.status.idle":"2022-03-18T08:42:49.299494Z","shell.execute_reply.started":"2022-03-18T08:41:35.831515Z","shell.execute_reply":"2022-03-18T08:42:49.298374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"articles\"></a>\n# Articles","metadata":{}},{"cell_type":"code","source":"pd.options.display.max_columns = None\narticles.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:20:28.034495Z","iopub.execute_input":"2022-03-17T13:20:28.034929Z","iopub.status.idle":"2022-03-17T13:20:28.073062Z","shell.execute_reply.started":"2022-03-17T13:20:28.034883Z","shell.execute_reply":"2022-03-17T13:20:28.072099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:20:29.870095Z","iopub.execute_input":"2022-03-17T13:20:29.87275Z","iopub.status.idle":"2022-03-17T13:20:30.118857Z","shell.execute_reply.started":"2022-03-17T13:20:29.87268Z","shell.execute_reply":"2022-03-17T13:20:30.117916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# number of unique values in each column\narticles.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:20:32.053005Z","iopub.execute_input":"2022-03-17T13:20:32.053729Z","iopub.status.idle":"2022-03-17T13:20:32.244294Z","shell.execute_reply.started":"2022-03-17T13:20:32.053674Z","shell.execute_reply":"2022-03-17T13:20:32.243254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"unique_values_articles\"></a>\n### Unique values of each column","metadata":{}},{"cell_type":"code","source":"# print unique values of each column\nfor c in articles.columns:\n    print(\"{} ({}) => {}\".format(c, articles[c].nunique(), articles[c].unique()))","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:20:34.680937Z","iopub.execute_input":"2022-03-17T13:20:34.681234Z","iopub.status.idle":"2022-03-17T13:20:35.022397Z","shell.execute_reply.started":"2022-03-17T13:20:34.681204Z","shell.execute_reply":"2022-03-17T13:20:35.020961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for c in articles.columns:\n    if articles[c].nunique() < 30 and type(articles[c].iloc[0]) is str:\n        print(\"{} ({}) => {}\".format(c, articles[c].nunique(), articles[c].unique()))","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:20:37.910714Z","iopub.execute_input":"2022-03-17T13:20:37.911191Z","iopub.status.idle":"2022-03-17T13:20:38.22488Z","shell.execute_reply.started":"2022-03-17T13:20:37.911145Z","shell.execute_reply":"2022-03-17T13:20:38.22351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### prod_name","metadata":{}},{"cell_type":"code","source":"# prod_name\nprint(articles['prod_name'].nunique())\nprod_name_top = articles.groupby(['prod_name']).count()['article_id'].sort_values(ascending=False).head(20)\nprod_name_top","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:20:40.561533Z","iopub.execute_input":"2022-03-17T13:20:40.561883Z","iopub.status.idle":"2022-03-17T13:20:40.910908Z","shell.execute_reply.started":"2022-03-17T13:20:40.561849Z","shell.execute_reply":"2022-03-17T13:20:40.909666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### product_type_name","metadata":{}},{"cell_type":"code","source":"# product_type_name\npd.options.display.max_rows = None\nprint(\"unique count : \", articles['product_type_name'].nunique())\nproduct_type_name_sorted = articles.groupby(['product_type_name']).count()['article_id'].sort_values(ascending=False)\nproduct_type_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:20:42.853637Z","iopub.execute_input":"2022-03-17T13:20:42.854434Z","iopub.status.idle":"2022-03-17T13:20:43.057051Z","shell.execute_reply.started":"2022-03-17T13:20:42.854363Z","shell.execute_reply":"2022-03-17T13:20:43.056253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"product_type_top = articles.groupby(['product_type_name']).count()['article_id'].sort_values(ascending=False).head(20)\nproduct_type_top","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:20:46.503353Z","iopub.execute_input":"2022-03-17T13:20:46.503722Z","iopub.status.idle":"2022-03-17T13:20:46.70167Z","shell.execute_reply.started":"2022-03-17T13:20:46.503677Z","shell.execute_reply":"2022-03-17T13:20:46.700573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 7))\nax = sns.barplot(x=product_type_top.values, y=product_type_top.index, color='xkcd:blue')\nax.set_xlabel('count by product type name')\nax.set_ylabel('product type name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:20:47.906344Z","iopub.execute_input":"2022-03-17T13:20:47.907437Z","iopub.status.idle":"2022-03-17T13:20:48.294104Z","shell.execute_reply.started":"2022-03-17T13:20:47.907373Z","shell.execute_reply":"2022-03-17T13:20:48.293025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 30))\nax = sns.barplot(x=product_type_name_sorted.values, y=product_type_name_sorted.index, color='xkcd:blue')\nax.set_xlabel('count by product type name')\nax.set_ylabel('product type name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:20:50.107086Z","iopub.execute_input":"2022-03-17T13:20:50.107654Z","iopub.status.idle":"2022-03-17T13:20:52.049741Z","shell.execute_reply.started":"2022-03-17T13:20:50.107601Z","shell.execute_reply":"2022-03-17T13:20:52.048728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### product_group_name","metadata":{}},{"cell_type":"code","source":"# product_group_name\nprint(articles['product_group_name'].nunique())\nproduct_group_name_sorted = articles.groupby(['product_group_name']).count()['article_id'].sort_values(ascending=False)\nproduct_group_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:00.736043Z","iopub.execute_input":"2022-03-17T13:21:00.736931Z","iopub.status.idle":"2022-03-17T13:21:00.943981Z","shell.execute_reply.started":"2022-03-17T13:21:00.736885Z","shell.execute_reply":"2022-03-17T13:21:00.943114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 6))\nax = sns.barplot(x=product_group_name_sorted.values, y=product_group_name_sorted.index, color='crimson')\nax.set_xlabel('count by product group name')\nax.set_ylabel('product group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:01.956344Z","iopub.execute_input":"2022-03-17T13:21:01.956903Z","iopub.status.idle":"2022-03-17T13:21:02.541481Z","shell.execute_reply.started":"2022-03-17T13:21:01.956865Z","shell.execute_reply":"2022-03-17T13:21:02.540395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pie_data = product_group_name_sorted[product_group_name_sorted.values > 100]\npie_data","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:04.211918Z","iopub.execute_input":"2022-03-17T13:21:04.212261Z","iopub.status.idle":"2022-03-17T13:21:04.22065Z","shell.execute_reply.started":"2022-03-17T13:21:04.212211Z","shell.execute_reply":"2022-03-17T13:21:04.220008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(16, 8))\ncolors = sns.color_palette('pastel')\nax.pie(pie_data, labels=pie_data.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:07.099801Z","iopub.execute_input":"2022-03-17T13:21:07.100505Z","iopub.status.idle":"2022-03-17T13:21:07.29178Z","shell.execute_reply.started":"2022-03-17T13:21:07.100465Z","shell.execute_reply":"2022-03-17T13:21:07.290338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### product_group_name & product_type_name","metadata":{}},{"cell_type":"code","source":"# product_group_name, product_type_name\narticles.groupby(['product_group_name', 'product_type_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:10.485724Z","iopub.execute_input":"2022-03-17T13:21:10.486019Z","iopub.status.idle":"2022-03-17T13:21:10.687387Z","shell.execute_reply.started":"2022-03-17T13:21:10.48599Z","shell.execute_reply":"2022-03-17T13:21:10.686342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### graphical_appearance_name","metadata":{}},{"cell_type":"code","source":"# graphical_appearance_name\nprint(articles['graphical_appearance_name'].nunique())\ngraphical_appearance_name_sorted = articles.groupby('graphical_appearance_name').count()['article_id'].sort_values(ascending=False)\ngraphical_appearance_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:15.1846Z","iopub.execute_input":"2022-03-17T13:21:15.184977Z","iopub.status.idle":"2022-03-17T13:21:15.392648Z","shell.execute_reply.started":"2022-03-17T13:21:15.18494Z","shell.execute_reply":"2022-03-17T13:21:15.39166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 10))\nax = sns.barplot(x=graphical_appearance_name_sorted.values, y=graphical_appearance_name_sorted.index, color='xkcd:orangered')\nax.set_xlabel('count by graphical_appearance_name')\nax.set_ylabel('graphical_appearance_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:17.481838Z","iopub.execute_input":"2022-03-17T13:21:17.482157Z","iopub.status.idle":"2022-03-17T13:21:17.936172Z","shell.execute_reply.started":"2022-03-17T13:21:17.482121Z","shell.execute_reply":"2022-03-17T13:21:17.935358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### colour_group_name","metadata":{}},{"cell_type":"code","source":"# colour_group_name\nprint(articles['colour_group_name'].nunique())\ncolour_group_name_sorted = articles.groupby(['colour_group_name']).count()['article_id'].sort_values(ascending=False)\ncolour_group_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:20.721408Z","iopub.execute_input":"2022-03-17T13:21:20.722447Z","iopub.status.idle":"2022-03-17T13:21:20.931429Z","shell.execute_reply.started":"2022-03-17T13:21:20.7224Z","shell.execute_reply":"2022-03-17T13:21:20.9303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 15))\nax = sns.barplot(x=colour_group_name_sorted.values, y=colour_group_name_sorted.index, color='purple')\nax.set_xlabel('count by colour_group_name')\nax.set_ylabel('colour_group_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:22.834413Z","iopub.execute_input":"2022-03-17T13:21:22.835532Z","iopub.status.idle":"2022-03-17T13:21:23.740911Z","shell.execute_reply.started":"2022-03-17T13:21:22.835474Z","shell.execute_reply":"2022-03-17T13:21:23.739909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### perceived_colour_value_name","metadata":{}},{"cell_type":"code","source":"# perceived_colour_value_name\nprint(articles['perceived_colour_value_name'].nunique())\narticles.groupby(['perceived_colour_value_name']).count()['article_id'].sort_values(ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:26.417438Z","iopub.execute_input":"2022-03-17T13:21:26.417807Z","iopub.status.idle":"2022-03-17T13:21:26.628658Z","shell.execute_reply.started":"2022-03-17T13:21:26.417772Z","shell.execute_reply":"2022-03-17T13:21:26.627653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 3))\nax = sns.histplot(data=articles, y='perceived_colour_value_name', color='xkcd:coral')\nax.set_xlabel('count by perceived_colour_value_name')\nax.set_ylabel('perceived_colour_value_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:28.349591Z","iopub.execute_input":"2022-03-17T13:21:28.349899Z","iopub.status.idle":"2022-03-17T13:21:28.794519Z","shell.execute_reply.started":"2022-03-17T13:21:28.349861Z","shell.execute_reply":"2022-03-17T13:21:28.793331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### perceived_colour_master_name","metadata":{}},{"cell_type":"code","source":"# perceived_colour_master_name\nprint(articles['perceived_colour_master_name'].nunique())\nperceived_colour_master_name_sorted = articles.groupby(['perceived_colour_master_name']).count()['article_id'].sort_values(ascending=False)\nperceived_colour_master_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:30.717421Z","iopub.execute_input":"2022-03-17T13:21:30.717766Z","iopub.status.idle":"2022-03-17T13:21:30.921993Z","shell.execute_reply.started":"2022-03-17T13:21:30.717734Z","shell.execute_reply":"2022-03-17T13:21:30.921036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 6))\nax = sns.barplot(x=perceived_colour_master_name_sorted.values, y=perceived_colour_master_name_sorted.index, color='darkgreen')\nax.set_xlabel('count by perceived_colour_master_name')\nax.set_ylabel('perceived_colour_master_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:32.301295Z","iopub.execute_input":"2022-03-17T13:21:32.301661Z","iopub.status.idle":"2022-03-17T13:21:32.669296Z","shell.execute_reply.started":"2022-03-17T13:21:32.301627Z","shell.execute_reply":"2022-03-17T13:21:32.66832Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### department_name","metadata":{}},{"cell_type":"code","source":"# department_name\npd.options.display.max_rows = None\nprint(articles['department_name'].nunique())\ndepartment_name_sorted = articles.groupby(['department_name']).count()['article_id'].sort_values(ascending=False)\ndepartment_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:34.180381Z","iopub.execute_input":"2022-03-17T13:21:34.180674Z","iopub.status.idle":"2022-03-17T13:21:34.382811Z","shell.execute_reply.started":"2022-03-17T13:21:34.180643Z","shell.execute_reply":"2022-03-17T13:21:34.382222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 50))\nax = sns.barplot(x=department_name_sorted.values, y=department_name_sorted.index, color='teal')\nax.set_xlabel('count by department_name')\nax.set_ylabel('department_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:38.098852Z","iopub.execute_input":"2022-03-17T13:21:38.099561Z","iopub.status.idle":"2022-03-17T13:21:42.401226Z","shell.execute_reply.started":"2022-03-17T13:21:38.099505Z","shell.execute_reply":"2022-03-17T13:21:42.400469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### index_group_name","metadata":{}},{"cell_type":"code","source":"# index_group_name, index_name\narticles.groupby(['index_group_name', 'index_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:42.40257Z","iopub.execute_input":"2022-03-17T13:21:42.403686Z","iopub.status.idle":"2022-03-17T13:21:42.591812Z","shell.execute_reply.started":"2022-03-17T13:21:42.403636Z","shell.execute_reply":"2022-03-17T13:21:42.590685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# index_group_name\nindex_group_name_sorted = articles.groupby(['index_group_name']).count()['article_id'].sort_values(ascending=False)\nindex_group_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:46.834923Z","iopub.execute_input":"2022-03-17T13:21:46.835288Z","iopub.status.idle":"2022-03-17T13:21:47.033509Z","shell.execute_reply.started":"2022-03-17T13:21:46.835237Z","shell.execute_reply":"2022-03-17T13:21:47.032329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 2))\nax = sns.barplot(x=index_group_name_sorted.values, y=index_group_name_sorted.index, color='indigo')\nax.set_xlabel('count by index group name')\nax.set_ylabel('index group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:47.922476Z","iopub.execute_input":"2022-03-17T13:21:47.922789Z","iopub.status.idle":"2022-03-17T13:21:48.181525Z","shell.execute_reply.started":"2022-03-17T13:21:47.922756Z","shell.execute_reply":"2022-03-17T13:21:48.180329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,5))\ncolors = sns.color_palette('pastel')\nax.pie(index_group_name_sorted, labels=index_group_name_sorted.index, colors = colors)\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:49.5715Z","iopub.execute_input":"2022-03-17T13:21:49.571896Z","iopub.status.idle":"2022-03-17T13:21:49.685357Z","shell.execute_reply.started":"2022-03-17T13:21:49.57185Z","shell.execute_reply":"2022-03-17T13:21:49.68463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### index_name","metadata":{}},{"cell_type":"code","source":"# index_name\nindex_name_sorted = articles.groupby(['index_name']).count()['article_id'].sort_values(ascending=False)\nindex_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:51.894208Z","iopub.execute_input":"2022-03-17T13:21:51.895275Z","iopub.status.idle":"2022-03-17T13:21:52.082488Z","shell.execute_reply.started":"2022-03-17T13:21:51.895208Z","shell.execute_reply":"2022-03-17T13:21:52.081486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 3))\nax = sns.barplot(x=index_name_sorted.values, y=index_name_sorted.index, color='teal')\nax.set_xlabel('count by index name')\nax.set_ylabel('index name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:52.2619Z","iopub.execute_input":"2022-03-17T13:21:52.2622Z","iopub.status.idle":"2022-03-17T13:21:52.537273Z","shell.execute_reply.started":"2022-03-17T13:21:52.262169Z","shell.execute_reply":"2022-03-17T13:21:52.536316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### section_name","metadata":{}},{"cell_type":"code","source":"# section_name\nprint(articles['section_name'].nunique())\nsection_name_sorted = articles.groupby(['section_name']).count()['article_id'].sort_values(ascending=False)\nsection_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:56.003392Z","iopub.execute_input":"2022-03-17T13:21:56.00391Z","iopub.status.idle":"2022-03-17T13:21:56.201214Z","shell.execute_reply.started":"2022-03-17T13:21:56.003867Z","shell.execute_reply":"2022-03-17T13:21:56.20033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 13))\nax = sns.barplot(x=section_name_sorted.values, y=section_name_sorted.index, color='teal')\nax.set_xlabel('count by section_name')\nax.set_ylabel('section_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:56.299389Z","iopub.execute_input":"2022-03-17T13:21:56.300452Z","iopub.status.idle":"2022-03-17T13:21:57.429146Z","shell.execute_reply.started":"2022-03-17T13:21:56.300405Z","shell.execute_reply":"2022-03-17T13:21:57.428162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### garment_group_name","metadata":{}},{"cell_type":"code","source":"# garment_group_name\nprint(articles['garment_group_name'].nunique())\ngarment_group_name_sorted = articles.groupby(['garment_group_name']).count()['article_id'].sort_values(ascending=False)\ngarment_group_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:57.759978Z","iopub.execute_input":"2022-03-17T13:21:57.760302Z","iopub.status.idle":"2022-03-17T13:21:57.962153Z","shell.execute_reply.started":"2022-03-17T13:21:57.76027Z","shell.execute_reply":"2022-03-17T13:21:57.961036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 6))\nax = sns.barplot(x=garment_group_name_sorted.values, y=garment_group_name_sorted.index, color='xkcd:magenta')\nax.set_xlabel('count by garment_group_name')\nax.set_ylabel('garment_group_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:21:57.964141Z","iopub.execute_input":"2022-03-17T13:21:57.964809Z","iopub.status.idle":"2022-03-17T13:21:58.357624Z","shell.execute_reply.started":"2022-03-17T13:21:57.964771Z","shell.execute_reply":"2022-03-17T13:21:58.356547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"customers\"></a>\n# Customers","metadata":{}},{"cell_type":"code","source":"customers.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:01.383895Z","iopub.execute_input":"2022-03-17T13:22:01.384281Z","iopub.status.idle":"2022-03-17T13:22:01.401055Z","shell.execute_reply.started":"2022-03-17T13:22:01.384234Z","shell.execute_reply":"2022-03-17T13:22:01.400344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:06.553283Z","iopub.execute_input":"2022-03-17T13:22:06.553602Z","iopub.status.idle":"2022-03-17T13:22:07.303634Z","shell.execute_reply.started":"2022-03-17T13:22:06.553571Z","shell.execute_reply":"2022-03-17T13:22:07.302506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:09.010434Z","iopub.execute_input":"2022-03-17T13:22:09.010759Z","iopub.status.idle":"2022-03-17T13:22:09.224644Z","shell.execute_reply.started":"2022-03-17T13:22:09.010729Z","shell.execute_reply":"2022-03-17T13:22:09.223446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:23.065229Z","iopub.execute_input":"2022-03-17T13:22:23.0656Z","iopub.status.idle":"2022-03-17T13:22:25.055932Z","shell.execute_reply.started":"2022-03-17T13:22:23.065567Z","shell.execute_reply":"2022-03-17T13:22:25.054985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"unique_values_customers\"></a>\n### Unique values of each column","metadata":{}},{"cell_type":"code","source":"for c in customers.columns:\n    print(\"{} ({}) {} => {}\".format(c, customers[c].nunique(), type(customers[c].iloc[0]), customers[c].unique()))","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:26.929669Z","iopub.execute_input":"2022-03-17T13:22:26.930503Z","iopub.status.idle":"2022-03-17T13:22:30.060797Z","shell.execute_reply.started":"2022-03-17T13:22:26.930462Z","shell.execute_reply":"2022-03-17T13:22:30.059573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for c in ['FN','Active','club_member_status', 'fashion_news_frequency']:\n    print('[{}] :\\n{}\\n'.format(c, customers[c].value_counts(dropna=False)))","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:30.689541Z","iopub.execute_input":"2022-03-17T13:22:30.690499Z","iopub.status.idle":"2022-03-17T13:22:31.158807Z","shell.execute_reply.started":"2022-03-17T13:22:30.690455Z","shell.execute_reply":"2022-03-17T13:22:31.157735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### FN","metadata":{}},{"cell_type":"code","source":"customers.FN.isna().sum()*100/len(customers)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T09:10:40.119922Z","iopub.execute_input":"2022-03-18T09:10:40.120892Z","iopub.status.idle":"2022-03-18T09:10:40.131241Z","shell.execute_reply.started":"2022-03-18T09:10:40.120831Z","shell.execute_reply":"2022-03-18T09:10:40.130027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers[customers.FN.notna()].head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T09:06:40.601493Z","iopub.execute_input":"2022-03-18T09:06:40.601913Z","iopub.status.idle":"2022-03-18T09:06:40.672982Z","shell.execute_reply.started":"2022-03-18T09:06:40.601882Z","shell.execute_reply":"2022-03-18T09:06:40.672343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Active","metadata":{}},{"cell_type":"code","source":"customers.Active.isna().sum()*100/len(customers)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T09:10:13.376862Z","iopub.execute_input":"2022-03-18T09:10:13.377833Z","iopub.status.idle":"2022-03-18T09:10:13.388083Z","shell.execute_reply.started":"2022-03-18T09:10:13.377783Z","shell.execute_reply":"2022-03-18T09:10:13.387036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers[customers.Active.notna()].head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T09:06:27.110106Z","iopub.execute_input":"2022-03-18T09:06:27.110679Z","iopub.status.idle":"2022-03-18T09:06:27.205146Z","shell.execute_reply.started":"2022-03-18T09:06:27.110627Z","shell.execute_reply":"2022-03-18T09:06:27.204448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers[((customers.Active.notna()) & (customers.FN.isna())) | ((customers.Active.isna()) & (customers.FN.notna()))].head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T09:09:47.618035Z","iopub.execute_input":"2022-03-18T09:09:47.618374Z","iopub.status.idle":"2022-03-18T09:09:47.652626Z","shell.execute_reply.started":"2022-03-18T09:09:47.618318Z","shell.execute_reply":"2022-03-18T09:09:47.652062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### club_member_status","metadata":{}},{"cell_type":"code","source":"# club_member_status\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=customers, x='club_member_status', color='green')\nax.set_xlabel('customers club_member_status')\nax.set_ylabel('customer count')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:34.54173Z","iopub.execute_input":"2022-03-17T13:22:34.542474Z","iopub.status.idle":"2022-03-17T13:22:36.541534Z","shell.execute_reply.started":"2022-03-17T13:22:34.542424Z","shell.execute_reply":"2022-03-17T13:22:36.540568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### fashion_news_frequency","metadata":{}},{"cell_type":"code","source":"# fashion_news_frequency\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=customers, x='fashion_news_frequency', color='orange')\nax.set_xlabel('customers fashion_news_frequency')\nax.set_ylabel('customer count')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T09:07:11.335576Z","iopub.execute_input":"2022-03-18T09:07:11.336036Z","iopub.status.idle":"2022-03-18T09:07:13.419106Z","shell.execute_reply.started":"2022-03-18T09:07:11.336001Z","shell.execute_reply":"2022-03-18T09:07:13.418183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### age","metadata":{}},{"cell_type":"code","source":"# age\nimport seaborn as sns\nfrom matplotlib import pyplot as plt\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=customers, x='age', bins=50, color='xkcd:azure')\nax.set_xlabel('customers age')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:50.395325Z","iopub.execute_input":"2022-03-17T13:22:50.396297Z","iopub.status.idle":"2022-03-17T13:22:50.946748Z","shell.execute_reply.started":"2022-03-17T13:22:50.396202Z","shell.execute_reply":"2022-03-17T13:22:50.945456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# average age\ncustomers['age'].mean()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:52.767407Z","iopub.execute_input":"2022-03-17T13:22:52.767755Z","iopub.status.idle":"2022-03-17T13:22:52.777787Z","shell.execute_reply.started":"2022-03-17T13:22:52.767724Z","shell.execute_reply":"2022-03-17T13:22:52.77651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nfrom matplotlib import pyplot as plt\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,2))\nax = sns.boxplot(data=customers, x='age', color='xkcd:azure')\nax.set_xlabel('customers age')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:53.192043Z","iopub.execute_input":"2022-03-17T13:22:53.192367Z","iopub.status.idle":"2022-03-17T13:22:53.448432Z","shell.execute_reply.started":"2022-03-17T13:22:53.192335Z","shell.execute_reply":"2022-03-17T13:22:53.447332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# average age with ACTIVE club_member_status\ncustomers[customers['club_member_status']== 'ACTIVE']['age'].mean()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:53.731684Z","iopub.execute_input":"2022-03-17T13:22:53.73197Z","iopub.status.idle":"2022-03-17T13:22:54.140626Z","shell.execute_reply.started":"2022-03-17T13:22:53.731941Z","shell.execute_reply":"2022-03-17T13:22:54.139766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# average age who fashion_news_frequency is 'Regularly'\ncustomers[customers['fashion_news_frequency']== 'Regularly']['age'].mean()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:22:55.664209Z","iopub.execute_input":"2022-03-17T13:22:55.665106Z","iopub.status.idle":"2022-03-17T13:22:55.96589Z","shell.execute_reply.started":"2022-03-17T13:22:55.665061Z","shell.execute_reply":"2022-03-17T13:22:55.965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=transactions></a>\n# Transactions","metadata":{}},{"cell_type":"code","source":"transactions_train.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:27:08.252138Z","iopub.execute_input":"2022-03-17T13:27:08.253063Z","iopub.status.idle":"2022-03-17T13:27:08.277533Z","shell.execute_reply.started":"2022-03-17T13:27:08.253Z","shell.execute_reply":"2022-03-17T13:27:08.276563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:27:10.277806Z","iopub.execute_input":"2022-03-17T13:27:10.278672Z","iopub.status.idle":"2022-03-17T13:27:10.291175Z","shell.execute_reply.started":"2022-03-17T13:27:10.278627Z","shell.execute_reply":"2022-03-17T13:27:10.29031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.float_format', '{:.4f}'.format)\ntransactions_train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:27:11.301619Z","iopub.execute_input":"2022-03-17T13:27:11.302686Z","iopub.status.idle":"2022-03-17T13:27:16.039786Z","shell.execute_reply.started":"2022-03-17T13:27:11.302633Z","shell.execute_reply":"2022-03-17T13:27:16.038748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:27:18.142759Z","iopub.execute_input":"2022-03-17T13:27:18.143077Z","iopub.status.idle":"2022-03-17T13:27:31.986877Z","shell.execute_reply.started":"2022-03-17T13:27:18.143048Z","shell.execute_reply":"2022-03-17T13:27:31.985926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### sales_channel_id","metadata":{}},{"cell_type":"code","source":"# sales_channel_id\ntransactions_train['sales_channel_id'].value_counts(dropna=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:27:38.657415Z","iopub.execute_input":"2022-03-17T13:27:38.658569Z","iopub.status.idle":"2022-03-17T13:27:38.829476Z","shell.execute_reply.started":"2022-03-17T13:27:38.658512Z","shell.execute_reply":"2022-03-17T13:27:38.828122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### price","metadata":{}},{"cell_type":"code","source":"# price\npd.set_option('display.float_format', '{:.4f}'.format)\ntransactions_train.describe()['price']","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:27:42.225001Z","iopub.execute_input":"2022-03-17T13:27:42.226186Z","iopub.status.idle":"2022-03-17T13:27:46.228842Z","shell.execute_reply.started":"2022-03-17T13:27:42.22614Z","shell.execute_reply":"2022-03-17T13:27:46.228109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# highest price\ntransactions_train.price.sort_values(ascending=False).head(10)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:27:49.426036Z","iopub.execute_input":"2022-03-17T13:27:49.426543Z","iopub.status.idle":"2022-03-17T13:27:56.6902Z","shell.execute_reply.started":"2022-03-17T13:27:49.42648Z","shell.execute_reply":"2022-03-17T13:27:56.689401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# lowest price\ntransactions_train.price.sort_values(ascending=False).tail(10)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:27:56.692135Z","iopub.execute_input":"2022-03-17T13:27:56.692627Z","iopub.status.idle":"2022-03-17T13:28:03.610797Z","shell.execute_reply.started":"2022-03-17T13:27:56.692584Z","shell.execute_reply":"2022-03-17T13:28:03.610217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"price_distribution\"></a>\n## Price Distribution","metadata":{}},{"cell_type":"code","source":"# price\nimport seaborn as sns\nfrom matplotlib import pyplot as plt\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(20, 5))\nax = sns.histplot(data=transactions_train, x='price', bins=100, color='xkcd:teal')\nax.set_xlabel('price')\nax.set_xlabel('transacion count')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:28:29.048566Z","iopub.execute_input":"2022-03-17T13:28:29.049536Z","iopub.status.idle":"2022-03-17T13:28:40.370739Z","shell.execute_reply.started":"2022-03-17T13:28:29.049495Z","shell.execute_reply":"2022-03-17T13:28:40.370019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(20,1))\nax = sns.boxplot(data=transactions_train, x='price', color='xkcd:pink')\nax.set_xlabel('Price outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:28:45.337524Z","iopub.execute_input":"2022-03-17T13:28:45.338115Z","iopub.status.idle":"2022-03-17T13:28:50.071947Z","shell.execute_reply.started":"2022-03-17T13:28:45.338078Z","shell.execute_reply":"2022-03-17T13:28:50.07131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"top_selling_articles\"></a>\n## Top selling articles","metadata":{}},{"cell_type":"code","source":"# Best selling article by total sales (판매 총액) \ntop_selling_article_by_total_sales = transactions_train.groupby('article_id')['price'].sum().sort_values(ascending=False).head(20)\ntop_selling_article_by_total_sales","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:28:56.786119Z","iopub.execute_input":"2022-03-17T13:28:56.786786Z","iopub.status.idle":"2022-03-17T13:28:57.970191Z","shell.execute_reply.started":"2022-03-17T13:28:56.786746Z","shell.execute_reply":"2022-03-17T13:28:57.96927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, idx in enumerate(top_selling_article_by_total_sales.index):    \n    print(\"[{}] {} ==> {}\".format(i, idx,articles[articles['article_id'] == idx][['product_group_name','product_type_name','index_name', 'garment_group_name']].values[0]))","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:28:59.877014Z","iopub.execute_input":"2022-03-17T13:28:59.877525Z","iopub.status.idle":"2022-03-17T13:28:59.916762Z","shell.execute_reply.started":"2022-03-17T13:28:59.877491Z","shell.execute_reply":"2022-03-17T13:28:59.91575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Best selling article by number\ntop_selling_article_by_number = transactions_train.groupby('article_id').count()['t_dat'].sort_values(ascending=False).head(20)\ntop_selling_article_by_number","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:29:22.600735Z","iopub.execute_input":"2022-03-17T13:29:22.601232Z","iopub.status.idle":"2022-03-17T13:29:31.677852Z","shell.execute_reply.started":"2022-03-17T13:29:22.601196Z","shell.execute_reply":"2022-03-17T13:29:31.676914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, idx in enumerate(top_selling_article_by_number.index):\n    print(\"[{}] {} ==> {}\".format(i, idx, articles[articles['article_id'] == idx][['product_group_name','product_type_name','index_name', 'garment_group_name']].values[0]))","metadata":{"execution":{"iopub.status.busy":"2022-03-17T00:10:56.161171Z","iopub.execute_input":"2022-03-17T00:10:56.161548Z","iopub.status.idle":"2022-03-17T00:10:56.197816Z","shell.execute_reply.started":"2022-03-17T00:10:56.161519Z","shell.execute_reply":"2022-03-17T00:10:56.196951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"top_customers\"></a>\n## Top 10 Customers","metadata":{}},{"cell_type":"code","source":"# top 10 customers with the most purchases (구매 회수)\ntop_customers_by_purchases = transactions_train.groupby('customer_id').count()['t_dat'].sort_values(ascending=False).head(10)\ntop_customers_by_purchases","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:30:24.500933Z","iopub.execute_input":"2022-03-17T13:30:24.501326Z","iopub.status.idle":"2022-03-17T13:30:46.682427Z","shell.execute_reply.started":"2022-03-17T13:30:24.501287Z","shell.execute_reply":"2022-03-17T13:30:46.681314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# age of top 10 customers\nfor i, idx in enumerate(top_customers_by_purchases.index):    \n    print(\"[{}] {} ==> {}\".format(i, idx, customers[customers['customer_id'] == idx]['age'].values[0]))","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:31:11.455802Z","iopub.execute_input":"2022-03-17T13:31:11.456108Z","iopub.status.idle":"2022-03-17T13:31:13.712725Z","shell.execute_reply.started":"2022-03-17T13:31:11.456077Z","shell.execute_reply":"2022-03-17T13:31:13.711827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# top 10 customers with the largest purchases (구매 금액)\ntop_customers_by_largest_purchases = transactions_train.groupby('customer_id')['price'].sum().sort_values(ascending=False).head(10)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:31:15.714447Z","iopub.execute_input":"2022-03-17T13:31:15.715564Z","iopub.status.idle":"2022-03-17T13:31:31.620705Z","shell.execute_reply.started":"2022-03-17T13:31:15.715503Z","shell.execute_reply":"2022-03-17T13:31:31.619802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# age of top 10 customers\nfor i, idx in enumerate(top_customers_by_largest_purchases.index):\n    print(\"[{}] {} ==> {}\".format(i, idx, customers[customers['customer_id'] == idx]['age'].values[0]))","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:31:55.776381Z","iopub.execute_input":"2022-03-17T13:31:55.77763Z","iopub.status.idle":"2022-03-17T13:31:57.987229Z","shell.execute_reply.started":"2022-03-17T13:31:55.777565Z","shell.execute_reply":"2022-03-17T13:31:57.986397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"price_outliers\"></a>\n## Check Price Outliers By Category","metadata":{}},{"cell_type":"code","source":"# merge transaction + customer + article\ntransactions_to_be_merged = transactions_train[['t_dat', 'customer_id', 'article_id', 'price']]\narticle_to_be_merged = articles[['article_id', 'prod_name', 'product_type_name', 'product_group_name', 'index_group_name']]\ncustomers_to_be_merged = customers[['customer_id', 'age']]\n","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:32:03.756499Z","iopub.execute_input":"2022-03-17T13:32:03.756783Z","iopub.status.idle":"2022-03-17T13:32:04.987445Z","shell.execute_reply.started":"2022-03-17T13:32:03.756755Z","shell.execute_reply":"2022-03-17T13:32:04.986434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_merged = transactions_to_be_merged.merge(article_to_be_merged, on='article_id', how='left')","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:32:06.34128Z","iopub.execute_input":"2022-03-17T13:32:06.341635Z","iopub.status.idle":"2022-03-17T13:32:16.757264Z","shell.execute_reply.started":"2022-03-17T13:32:06.3416Z","shell.execute_reply":"2022-03-17T13:32:16.756241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_merged = transactions_merged.merge(customers_to_be_merged, on='customer_id', how='left')","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:32:20.966316Z","iopub.execute_input":"2022-03-17T13:32:20.967092Z","iopub.status.idle":"2022-03-17T13:32:42.028623Z","shell.execute_reply.started":"2022-03-17T13:32:20.967056Z","shell.execute_reply":"2022-03-17T13:32:42.027894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_merged.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:32:55.593778Z","iopub.execute_input":"2022-03-17T13:32:55.594117Z","iopub.status.idle":"2022-03-17T13:32:55.611975Z","shell.execute_reply.started":"2022-03-17T13:32:55.594085Z","shell.execute_reply":"2022-03-17T13:32:55.610863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"produt_group_names = transactions_merged['product_group_name'].unique()\nprodut_group_names","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:34:54.730843Z","iopub.execute_input":"2022-03-17T13:34:54.731416Z","iopub.status.idle":"2022-03-17T13:34:57.646757Z","shell.execute_reply.started":"2022-03-17T13:34:54.731379Z","shell.execute_reply":"2022-03-17T13:34:57.645642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"box_color = ['xkcd:pink', 'xkcd:blue', 'xkcd:teal', 'xkcd:goldenrod']\nsns.set_style(\"darkgrid\")\nfor i, name in enumerate(produt_group_names):\n    figure, ax = plt.subplots(figsize=(20,1))\n    ax = sns.boxplot(data=transactions_merged[transactions_merged['product_group_name']== name], x='price', color=box_color[i%len(box_color)])\n    ax.set_ylabel(name)\n    plt.show()\nax.set_xlabel('Price outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:35:02.722326Z","iopub.execute_input":"2022-03-17T13:35:02.722611Z","iopub.status.idle":"2022-03-17T13:36:52.978191Z","shell.execute_reply.started":"2022-03-17T13:35:02.722583Z","shell.execute_reply":"2022-03-17T13:36:52.976953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"top_selling_product_group\"></a>\n## Top Selling Product Group","metadata":{}},{"cell_type":"code","source":"# top selling product group by total sales\ntop_selling_product_group = transactions_merged.groupby('product_group_name')['price'].sum().sort_values(ascending=False)\ntop_selling_product_group","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:03.913842Z","iopub.execute_input":"2022-03-17T13:37:03.91417Z","iopub.status.idle":"2022-03-17T13:37:07.465471Z","shell.execute_reply.started":"2022-03-17T13:37:03.914138Z","shell.execute_reply":"2022-03-17T13:37:07.464868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 6))\nax = sns.barplot(x=top_selling_product_group.values, y=top_selling_product_group.index, color='xkcd:magenta')\nax.set_xlabel('total sales by product group name')\nax.set_ylabel('product group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:14.169844Z","iopub.execute_input":"2022-03-17T13:37:14.170693Z","iopub.status.idle":"2022-03-17T13:37:14.54416Z","shell.execute_reply.started":"2022-03-17T13:37:14.170641Z","shell.execute_reply":"2022-03-17T13:37:14.54305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(16, 8))\ncolors = sns.color_palette('pastel')\nax.pie(top_selling_product_group, labels=top_selling_product_group.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:16.147486Z","iopub.execute_input":"2022-03-17T13:37:16.147852Z","iopub.status.idle":"2022-03-17T13:37:16.4696Z","shell.execute_reply.started":"2022-03-17T13:37:16.147817Z","shell.execute_reply":"2022-03-17T13:37:16.468711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# top selling prouct_group by number\ntop_selling_product_group_by_number = transactions_merged.groupby('product_group_name')['article_id'].count().sort_values(ascending=False)\ntop_selling_product_group_by_number","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:18.399415Z","iopub.execute_input":"2022-03-17T13:37:18.399759Z","iopub.status.idle":"2022-03-17T13:37:22.102747Z","shell.execute_reply.started":"2022-03-17T13:37:18.39972Z","shell.execute_reply":"2022-03-17T13:37:22.101713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 6))\nax = sns.barplot(x=top_selling_product_group_by_number.values, y=top_selling_product_group_by_number.index, color='xkcd:blue')\nax.set_xlabel('top selling group by number')\nax.set_ylabel('product group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:25.119292Z","iopub.execute_input":"2022-03-17T13:37:25.119867Z","iopub.status.idle":"2022-03-17T13:37:25.50371Z","shell.execute_reply.started":"2022-03-17T13:37:25.119815Z","shell.execute_reply":"2022-03-17T13:37:25.502475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(16, 8))\ncolors = sns.color_palette('pastel')\nax.pie(top_selling_product_group_by_number, labels=top_selling_product_group_by_number.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:27.340473Z","iopub.execute_input":"2022-03-17T13:37:27.340847Z","iopub.status.idle":"2022-03-17T13:37:27.656559Z","shell.execute_reply.started":"2022-03-17T13:37:27.340812Z","shell.execute_reply":"2022-03-17T13:37:27.655557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# top selling index_group by total sales\ntop_selling_index_group = transactions_merged.groupby('index_group_name')['price'].sum().sort_values(ascending=False)\ntop_selling_index_group","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:30.448134Z","iopub.execute_input":"2022-03-17T13:37:30.448794Z","iopub.status.idle":"2022-03-17T13:37:34.029891Z","shell.execute_reply.started":"2022-03-17T13:37:30.448756Z","shell.execute_reply":"2022-03-17T13:37:34.028635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 2))\nax = sns.barplot(x=top_selling_index_group.values, y=top_selling_index_group.index, color='xkcd:magenta')\nax.set_xlabel('total sales by index group name')\nax.set_ylabel('index group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:37.34534Z","iopub.execute_input":"2022-03-17T13:37:37.345669Z","iopub.status.idle":"2022-03-17T13:37:37.604952Z","shell.execute_reply.started":"2022-03-17T13:37:37.345638Z","shell.execute_reply":"2022-03-17T13:37:37.603876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 5))\ncolors = sns.color_palette('pastel')\nax.pie(top_selling_index_group, labels=top_selling_index_group.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:39.217341Z","iopub.execute_input":"2022-03-17T13:37:39.217637Z","iopub.status.idle":"2022-03-17T13:37:39.353675Z","shell.execute_reply.started":"2022-03-17T13:37:39.217608Z","shell.execute_reply":"2022-03-17T13:37:39.352632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# top selling index_group by number\ntop_selling_index_group_by_number = transactions_merged.groupby('index_group_name')['article_id'].count().sort_values(ascending=False)\ntop_selling_index_group_by_number","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:42.364986Z","iopub.execute_input":"2022-03-17T13:37:42.365539Z","iopub.status.idle":"2022-03-17T13:37:45.813405Z","shell.execute_reply.started":"2022-03-17T13:37:42.365504Z","shell.execute_reply":"2022-03-17T13:37:45.812513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,2))\nax = sns.barplot(x=top_selling_index_group_by_number.values, y=top_selling_index_group_by_number.index, color='xkcd:blue')\nax.set_xlabel('top selling group by number')\nax.set_ylabel('index group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:48.074061Z","iopub.execute_input":"2022-03-17T13:37:48.075018Z","iopub.status.idle":"2022-03-17T13:37:48.351119Z","shell.execute_reply.started":"2022-03-17T13:37:48.074967Z","shell.execute_reply":"2022-03-17T13:37:48.350175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 5))\ncolors = sns.color_palette('pastel')\nax.pie(top_selling_index_group_by_number, labels=top_selling_index_group_by_number.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:37:50.847281Z","iopub.execute_input":"2022-03-17T13:37:50.847642Z","iopub.status.idle":"2022-03-17T13:37:50.98596Z","shell.execute_reply.started":"2022-03-17T13:37:50.8476Z","shell.execute_reply":"2022-03-17T13:37:50.984771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"product_groups_together\"></a>\n## Distinct product groups bought together","metadata":{}},{"cell_type":"code","source":"sample_transactions = transactions_merged.head(100000)\narticles_per_customer = sample_transactions.groupby('customer_id').product_group_name.agg(list)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T13:52:36.12321Z","iopub.execute_input":"2022-03-17T13:52:36.123823Z","iopub.status.idle":"2022-03-17T13:52:36.687902Z","shell.execute_reply.started":"2022-03-17T13:52:36.123783Z","shell.execute_reply":"2022-03-17T13:52:36.687124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = articles_per_customer.map(lambda x:\"|\".join(x)).str.get_dummies()\nx = df.values\ny = np.dot(x.T,x)\nn_pairs = pd.DataFrame(y,index = df.columns,columns = df.columns)\nnp.fill_diagonal(n_pairs.values,0)\nn_pairs","metadata":{"execution":{"iopub.status.busy":"2022-03-17T14:26:18.856191Z","iopub.execute_input":"2022-03-17T14:26:18.856569Z","iopub.status.idle":"2022-03-17T14:26:19.097293Z","shell.execute_reply.started":"2022-03-17T14:26:18.85653Z","shell.execute_reply":"2022-03-17T14:26:19.09611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"product_types_together\"></a>\n## Distinct product types bought together","metadata":{}},{"cell_type":"code","source":"articles_per_customer = sample_transactions.groupby('customer_id').product_type_name.agg(list)\ndf = articles_per_customer.map(lambda x:\"|\".join(x)).str.get_dummies()\nx = df.values\ny = np.dot(x.T,x)\nn_pairs = pd.DataFrame(y,index = df.columns,columns = df.columns)\nnp.fill_diagonal(n_pairs.values,0)\nn_pairs","metadata":{"execution":{"iopub.status.busy":"2022-03-17T14:31:45.612452Z","iopub.execute_input":"2022-03-17T14:31:45.612813Z","iopub.status.idle":"2022-03-17T14:31:48.86873Z","shell.execute_reply.started":"2022-03-17T14:31:45.612778Z","shell.execute_reply":"2022-03-17T14:31:48.867953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"group_per_postal\"></a>\n## Top product group per postal code","metadata":{}},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"code","source":"transactions_to_be_merged = transactions_train[['t_dat', 'customer_id', 'article_id', 'price']]\narticle_to_be_merged = articles[['article_id', 'prod_name', 'product_type_name', 'product_group_name', 'index_group_name']]\ncustomers_to_be_merged = customers[['customer_id', 'age','postal_code']]\ntransactions_merged = transactions_to_be_merged.merge(article_to_be_merged, on='article_id', how='left')\ntransactions_merged = transactions_merged.merge(customers_to_be_merged, on='customer_id', how='left')","metadata":{"execution":{"iopub.status.busy":"2022-03-18T07:32:53.484166Z","iopub.execute_input":"2022-03-18T07:32:53.484554Z","iopub.status.idle":"2022-03-18T07:33:29.730010Z","shell.execute_reply.started":"2022-03-18T07:32:53.484517Z","shell.execute_reply":"2022-03-18T07:33:29.728886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_merged.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T07:35:02.066868Z","iopub.execute_input":"2022-03-18T07:35:02.067708Z","iopub.status.idle":"2022-03-18T07:35:02.096585Z","shell.execute_reply.started":"2022-03-18T07:35:02.067665Z","shell.execute_reply":"2022-03-18T07:35:02.095861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_merged.groupby('postal_code').product_group_name.value_counts().head(20)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T14:46:31.725949Z","iopub.execute_input":"2022-03-17T14:46:31.726337Z","iopub.status.idle":"2022-03-17T14:47:01.101474Z","shell.execute_reply.started":"2022-03-17T14:46:31.726301Z","shell.execute_reply":"2022-03-17T14:47:01.100478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = transactions_merged.head(100000).groupby('postal_code').product_group_name.value_counts()\nd = {}\nmax_val = {}\nfor x,y in df.index.values:\n    if x not in d:\n        d[x] = y\n        max_val[x] = df[(x,y)]\n    else:\n        if df[(x,y)]>max_val[x]:\n            max_val[x] = df[(x,y)]\n            d[x] = y\ntop_group_per_code = pd.Series(d)\ntop_group_per_code.head(10)\n","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:00:41.663993Z","iopub.execute_input":"2022-03-17T15:00:41.665433Z","iopub.status.idle":"2022-03-17T15:00:42.974016Z","shell.execute_reply.started":"2022-03-17T15:00:41.665377Z","shell.execute_reply":"2022-03-17T15:00:42.973014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"seasonal\"></a>\n## Seasonal/all year round transactions","metadata":{}},{"cell_type":"code","source":"df = transactions_merged.groupby('product_group_name').t_dat.value_counts().reset_index(level=0)\ndf = df.sort_index().rename(columns = {'t_dat':'counts'})\ndf.index = pd.to_datetime(df.index)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:18:22.522061Z","iopub.execute_input":"2022-03-18T08:18:22.522369Z","iopub.status.idle":"2022-03-18T08:18:34.389326Z","shell.execute_reply.started":"2022-03-18T08:18:22.522334Z","shell.execute_reply":"2022-03-18T08:18:34.387987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accessories = df[df.product_group_name == 'Accessories']\nswimwear = df[df.product_group_name == 'Swimwear']","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:19:54.884064Z","iopub.execute_input":"2022-03-18T08:19:54.884624Z","iopub.status.idle":"2022-03-18T08:19:54.894292Z","shell.execute_reply.started":"2022-03-18T08:19:54.884559Z","shell.execute_reply":"2022-03-18T08:19:54.893411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from statsmodels.tsa.seasonal import STL","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:32:55.522363Z","iopub.execute_input":"2022-03-18T08:32:55.522767Z","iopub.status.idle":"2022-03-18T08:32:55.645202Z","shell.execute_reply.started":"2022-03-18T08:32:55.522729Z","shell.execute_reply":"2022-03-18T08:32:55.644203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 5))\nax = sns.lineplot(x = accessories.index,y = accessories.counts,color = 'teal')\nax.set_xlim([pd.to_datetime('2018-09-20'),\n             pd.to_datetime('2020-09-22')])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:18:57.740646Z","iopub.execute_input":"2022-03-18T08:18:57.741116Z","iopub.status.idle":"2022-03-18T08:18:58.186574Z","shell.execute_reply.started":"2022-03-18T08:18:57.741062Z","shell.execute_reply":"2022-03-18T08:18:58.185703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 5))\nax = sns.lineplot(x = swimwear.index,y = swimwear.counts,color = 'teal')\nax.set_xlim([pd.to_datetime('2018-09-20'),\n             pd.to_datetime('2020-09-22')])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:19:57.218400Z","iopub.execute_input":"2022-03-18T08:19:57.218741Z","iopub.status.idle":"2022-03-18T08:19:57.687172Z","shell.execute_reply.started":"2022-03-18T08:19:57.218702Z","shell.execute_reply":"2022-03-18T08:19:57.686249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stl = STL(swimwear.counts, seasonal=13)\nres = stl.fit()\nfig = res.plot()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:34:09.535925Z","iopub.execute_input":"2022-03-18T08:34:09.536715Z","iopub.status.idle":"2022-03-18T08:34:11.198701Z","shell.execute_reply.started":"2022-03-18T08:34:09.536670Z","shell.execute_reply":"2022-03-18T08:34:11.197774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"sales_distribution\"></a>\n# Sales Distribution","metadata":{}},{"cell_type":"code","source":"# total sales\ntotal_sales = transactions_train['price'].sum()\ntotal_sales","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:37:53.126171Z","iopub.execute_input":"2022-03-18T08:37:53.126500Z","iopub.status.idle":"2022-03-18T08:37:53.203027Z","shell.execute_reply.started":"2022-03-18T08:37:53.126467Z","shell.execute_reply":"2022-03-18T08:37:53.201770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# calcurate and sort sales for each article\narticle_sorted_by_sales = transactions_train.groupby('article_id')['price'].sum().sort_values(ascending=False)\narticle_sorted_by_sales.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:09.63168Z","iopub.execute_input":"2022-03-17T15:02:09.631973Z","iopub.status.idle":"2022-03-17T15:02:10.959066Z","shell.execute_reply.started":"2022-03-17T15:02:09.63194Z","shell.execute_reply":"2022-03-17T15:02:10.958398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article_sorted_by_sales.tail()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:12.339508Z","iopub.execute_input":"2022-03-17T15:02:12.340313Z","iopub.status.idle":"2022-03-17T15:02:12.347993Z","shell.execute_reply.started":"2022-03-17T15:02:12.340265Z","shell.execute_reply":"2022-03-17T15:02:12.3468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# total number of articles\narticle_sorted_by_sales.shape[0]","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:13.239064Z","iopub.execute_input":"2022-03-17T15:02:13.239415Z","iopub.status.idle":"2022-03-17T15:02:13.245105Z","shell.execute_reply.started":"2022-03-17T15:02:13.239383Z","shell.execute_reply":"2022-03-17T15:02:13.24432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article_sorted_by_sales.describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:13.595073Z","iopub.execute_input":"2022-03-17T15:02:13.595852Z","iopub.status.idle":"2022-03-17T15:02:13.614366Z","shell.execute_reply.started":"2022-03-17T15:02:13.595803Z","shell.execute_reply":"2022-03-17T15:02:13.613385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sales distribution of all articleas\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(20, 5))\nax = sns.histplot(article_sorted_by_sales.values, bins=100, color='xkcd:blue')\nax.set_xlabel('distribution of sales')\nax.set_ylabel('sales')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:14.999352Z","iopub.execute_input":"2022-03-17T15:02:14.999815Z","iopub.status.idle":"2022-03-17T15:02:15.576519Z","shell.execute_reply.started":"2022-03-17T15:02:14.999764Z","shell.execute_reply":"2022-03-17T15:02:15.575346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sales distribution of top 100 selling articles\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(20, 5))\nax = sns.histplot(article_sorted_by_sales.values[:100], bins=100, color='xkcd:blue')\nax.set_xlabel('distribution of sales')\nax.set_ylabel('sales')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:16.744404Z","iopub.execute_input":"2022-03-17T15:02:16.745559Z","iopub.status.idle":"2022-03-17T15:02:17.229663Z","shell.execute_reply.started":"2022-03-17T15:02:16.745493Z","shell.execute_reply":"2022-03-17T15:02:17.228603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sales graph of articles sorted by sales volume\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(8,8))\nax = sns.lineplot(x=range(article_sorted_by_sales.shape[0]), y=article_sorted_by_sales.values, color='xkcd:blue')\nax.set_xlabel('article sales ranking')\nax.set_ylabel('sales')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:18.116068Z","iopub.execute_input":"2022-03-17T15:02:18.116414Z","iopub.status.idle":"2022-03-17T15:02:22.958034Z","shell.execute_reply.started":"2022-03-17T15:02:18.116383Z","shell.execute_reply":"2022-03-17T15:02:22.956674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# how much top selling 1% articles contribute to overall sales\ntop_1p_articles = article_sorted_by_sales.head(int(article_sorted_by_sales.shape[0]*0.01))\ntop_1p_articles.sum()/ total_sales","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:22.96033Z","iopub.execute_input":"2022-03-17T15:02:22.960925Z","iopub.status.idle":"2022-03-17T15:02:22.970176Z","shell.execute_reply.started":"2022-03-17T15:02:22.960862Z","shell.execute_reply":"2022-03-17T15:02:22.968886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# how much top selling n% articles contribute to overall sales\nn_pct_sales = [article_sorted_by_sales.head(int(article_sorted_by_sales.shape[0]*0.01*(n))).sum() / total_sales * 100 for n in range (1, 100+1)]\n# n_pct_sales","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:22.971553Z","iopub.execute_input":"2022-03-17T15:02:22.972138Z","iopub.status.idle":"2022-03-17T15:02:23.017382Z","shell.execute_reply.started":"2022-03-17T15:02:22.972106Z","shell.execute_reply":"2022-03-17T15:02:23.016453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# top selling n% articles => contribution percentage to total sales\nfor n in range(100):\n    print(\"{:3}% => {:3.2f} % sales (+{:3.2f})%\".format(n+1, n_pct_sales[n], n_pct_sales[n] - n_pct_sales[n-1] if n>0 else 0))\n    print(\"-------------------------------\") if (n+1) % 10 == 0 and (n+1) != 0 else 0","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:26.176962Z","iopub.execute_input":"2022-03-17T15:02:26.1773Z","iopub.status.idle":"2022-03-17T15:02:26.202584Z","shell.execute_reply.started":"2022-03-17T15:02:26.177267Z","shell.execute_reply":"2022-03-17T15:02:26.201554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(6,6))\nax = sns.lineplot(x=range(1, 100+1), y=n_pct_sales, color='xkcd:blue')\nax.set_xlabel('n percent articles')\nax.set_ylabel('sales')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T15:02:28.737297Z","iopub.execute_input":"2022-03-17T15:02:28.737612Z","iopub.status.idle":"2022-03-17T15:02:29.00481Z","shell.execute_reply.started":"2022-03-17T15:02:28.737582Z","shell.execute_reply":"2022-03-17T15:02:29.00356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#total spendings per day\ntime_transactions = transactions_train.groupby('t_dat').price.sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:43:50.316754Z","iopub.execute_input":"2022-03-18T08:43:50.317057Z","iopub.status.idle":"2022-03-18T08:43:53.244373Z","shell.execute_reply.started":"2022-03-18T08:43:50.317021Z","shell.execute_reply":"2022-03-18T08:43:53.243499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"time_transactions.index = pd.to_datetime(time_transactions.index)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:45:09.010353Z","iopub.execute_input":"2022-03-18T08:45:09.011242Z","iopub.status.idle":"2022-03-18T08:45:09.021164Z","shell.execute_reply.started":"2022-03-18T08:45:09.011181Z","shell.execute_reply":"2022-03-18T08:45:09.020547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(8,8))\nax = sns.lineplot(x=time_transactions.index, y=time_transactions.values, color='xkcd:blue')\nax.set_xlabel('date')\nax.set_ylabel('total sales')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:46:25.824250Z","iopub.execute_input":"2022-03-18T08:46:25.824547Z","iopub.status.idle":"2022-03-18T08:46:26.281180Z","shell.execute_reply.started":"2022-03-18T08:46:25.824516Z","shell.execute_reply":"2022-03-18T08:46:26.280050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# day of maximum spending\nx = str(time_transactions.idxmax()).split(' ')\ndate = x[0]\nprint(time_transactions.max())\ndate","metadata":{"execution":{"iopub.status.busy":"2022-03-18T08:58:04.288659Z","iopub.execute_input":"2022-03-18T08:58:04.289026Z","iopub.status.idle":"2022-03-18T08:58:04.297505Z","shell.execute_reply.started":"2022-03-18T08:58:04.288991Z","shell.execute_reply":"2022-03-18T08:58:04.296936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}}]}