{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n#for dirname, _, filenames in os.walk('/kaggle/input'):\n    #for filename in filenames:\n        #print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-28T23:57:16.155512Z","iopub.execute_input":"2022-03-28T23:57:16.155873Z","iopub.status.idle":"2022-03-28T23:57:16.161084Z","shell.execute_reply.started":"2022-03-28T23:57:16.155837Z","shell.execute_reply":"2022-03-28T23:57:16.160165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\nfrom pylab import rcParams","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:16.815456Z","iopub.execute_input":"2022-03-28T23:57:16.816191Z","iopub.status.idle":"2022-03-28T23:57:17.913714Z","shell.execute_reply.started":"2022-03-28T23:57:16.816148Z","shell.execute_reply":"2022-03-28T23:57:17.912822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/h-and-m-personalized-fashion-recommendations/'","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:17.915350Z","iopub.execute_input":"2022-03-28T23:57:17.915603Z","iopub.status.idle":"2022-03-28T23:57:17.920016Z","shell.execute_reply.started":"2022-03-28T23:57:17.915575Z","shell.execute_reply":"2022-03-28T23:57:17.918992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! ls {path}","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:18.179208Z","iopub.execute_input":"2022-03-28T23:57:18.180154Z","iopub.status.idle":"2022-03-28T23:57:18.959632Z","shell.execute_reply.started":"2022-03-28T23:57:18.180107Z","shell.execute_reply":"2022-03-28T23:57:18.958680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Articles","metadata":{}},{"cell_type":"code","source":"articles_df = pd.read_csv(path+\"articles.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-29T00:00:26.728477Z","iopub.execute_input":"2022-03-29T00:00:26.728858Z","iopub.status.idle":"2022-03-29T00:00:27.392338Z","shell.execute_reply.started":"2022-03-29T00:00:26.728818Z","shell.execute_reply":"2022-03-29T00:00:27.391185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(articles_df.shape)\narticles_df.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:19.992927Z","iopub.execute_input":"2022-03-28T23:57:19.993268Z","iopub.status.idle":"2022-03-28T23:57:20.031485Z","shell.execute_reply.started":"2022-03-28T23:57:19.993233Z","shell.execute_reply":"2022-03-28T23:57:20.030660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:20.162132Z","iopub.execute_input":"2022-03-28T23:57:20.162752Z","iopub.status.idle":"2022-03-28T23:57:20.331194Z","shell.execute_reply.started":"2022-03-28T23:57:20.162712Z","shell.execute_reply":"2022-03-28T23:57:20.330320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"var = 'graphical_appearance_name'\nprint(len(articles_df[var].unique()))\nprint(articles_df[var].unique())","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:20.904438Z","iopub.execute_input":"2022-03-28T23:57:20.905148Z","iopub.status.idle":"2022-03-28T23:57:20.934300Z","shell.execute_reply.started":"2022-03-28T23:57:20.905094Z","shell.execute_reply":"2022-03-28T23:57:20.933438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.rcParams['text.color'] = 'black'\nplt.rcParams['axes.labelcolor'] = 'black'\nplt.rcParams['font.size'] = 10\n\nax = articles_df['product_group_name'].value_counts(normalize=True).mul(100).round(1).plot(kind = 'bar', color = 'blue', figsize = (10, 5),\n                                                    title = 'Bar graph of Product Group Name')\nax.set_xlabel(\"Product Group Name\", fontsize = 12)\nax.set_ylabel(\"Percentage %\", fontsize = 12)\nplt.tick_params(labelsize = 10)\nplt.grid()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:21.543288Z","iopub.execute_input":"2022-03-28T23:57:21.543654Z","iopub.status.idle":"2022-03-28T23:57:21.983465Z","shell.execute_reply.started":"2022-03-28T23:57:21.543585Z","shell.execute_reply":"2022-03-28T23:57:21.982557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"From the above graph, it can be seen that the articles of product group 'Garment Upper Body' and 'Garment Lower Body' constitute more than 65 % of the total in the dataset.","metadata":{}},{"cell_type":"code","source":"ax = articles_df['product_type_name'].value_counts(normalize=True, ascending = False).mul(100).round(1).plot(kind = 'bar', color = 'purple', figsize = (24, 8),\n                                                         title = 'Bar graphs on Product Type Name')\nax.set_xlabel('Product Type Name', fontsize = 12)\nax.set_ylabel('Percentage %', fontsize=12)\nplt.tick_params(labelsize = 10)\nplt.grid()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:22.096134Z","iopub.execute_input":"2022-03-28T23:57:22.096974Z","iopub.status.idle":"2022-03-28T23:57:24.451544Z","shell.execute_reply.started":"2022-03-28T23:57:22.096932Z","shell.execute_reply":"2022-03-28T23:57:24.450597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Notice how {Trousers, Dress, Sweater and T-Shirt} dominate the percentage distribution of articles in the articles data. These types of products are sold more than any other product type simply because they are worn and needed by both genders and across all age groups. The product types that follow this subset in percentage distribution, are {Jackets, Shorts, Hoodie}. They are also quite popular in both genders and among people from different age groups but their distribution is comparitively low probably because of the seasonality effect.","metadata":{}},{"cell_type":"code","source":"ax = articles_df['graphical_appearance_name'].value_counts(normalize=True, ascending = False).mul(100).round(1).plot(kind = 'bar', color = 'green', figsize = (10, 5),\n                                                            title = 'Bar graph on Graphical Appearance Name')\nax.set_xlabel('Graphical Appearance Name')\nax.set_ylabel('Frequency')\nplt.tick_params(labelsize = 12)\nplt.grid()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:24.453896Z","iopub.execute_input":"2022-03-28T23:57:24.454481Z","iopub.status.idle":"2022-03-28T23:57:24.920566Z","shell.execute_reply.started":"2022-03-28T23:57:24.454432Z","shell.execute_reply":"2022-03-28T23:57:24.919575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most of the articles are solid in graphical appearance.","metadata":{}},{"cell_type":"code","source":"ax = articles_df['section_name'].value_counts(normalize=True, ascending = False).mul(100).round(1).plot(kind = 'bar', color = 'red', figsize = (18, 5),\n                                                    title = 'Bar graph of Section Name')\nax.set_xlabel(\"Section Name\", fontsize = 12)\nax.set_ylabel(\"Frequency\", fontsize = 12)\nplt.tick_params(labelsize = 10)\nplt.grid()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:24.922089Z","iopub.execute_input":"2022-03-28T23:57:24.922980Z","iopub.status.idle":"2022-03-28T23:57:26.443752Z","shell.execute_reply.started":"2022-03-28T23:57:24.922936Z","shell.execute_reply":"2022-03-28T23:57:26.442888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Clear observation: Women and Kid section dominates the articles distribution.","metadata":{}},{"cell_type":"code","source":"ax = articles_df['index_group_name'].value_counts(normalize=True, ascending = False).mul(100).round(1).plot(kind = 'bar', color = 'orange', figsize = (10, 5),\n                                                    title = 'Bar graph of Index Group Name')\nax.set_xlabel(\"Index Group Name\", fontsize = 12)\nax.set_ylabel(\"Frequency\", fontsize = 12)\nplt.tick_params(labelsize = 10)\nplt.grid()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:26.446168Z","iopub.execute_input":"2022-03-28T23:57:26.446692Z","iopub.status.idle":"2022-03-28T23:57:26.696999Z","shell.execute_reply.started":"2022-03-28T23:57:26.446644Z","shell.execute_reply":"2022-03-28T23:57:26.696411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Consistent to the distribution of the section column, Ladieswear and Childrenwear dominate the group distritbution of the articles. Articles of Sports group are less than 5%.","metadata":{}},{"cell_type":"code","source":"ax = articles_df['garment_group_name'].value_counts(normalize=True, ascending = False).mul(100).round(1).plot(kind = 'bar', color = 'brown', figsize = (10, 5),\n                                                    title = 'Bar graph of Garment Group Name')\nax.set_xlabel(\"Garment Group Name\", fontsize = 12)\nax.set_ylabel(\"Frequency\", fontsize = 12)\nplt.tick_params(labelsize = 10)\nplt.grid()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:26.698106Z","iopub.execute_input":"2022-03-28T23:57:26.698918Z","iopub.status.idle":"2022-03-28T23:57:27.105165Z","shell.execute_reply.started":"2022-03-28T23:57:26.698879Z","shell.execute_reply":"2022-03-28T23:57:27.104280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"By garment group name, Jerseys make about 30% of the articles followed by Accessories which is 10%.","metadata":{}},{"cell_type":"code","source":"del(articles_df)\ndel(ax)","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:27.106683Z","iopub.execute_input":"2022-03-28T23:57:27.106916Z","iopub.status.idle":"2022-03-28T23:57:27.110736Z","shell.execute_reply.started":"2022-03-28T23:57:27.106888Z","shell.execute_reply":"2022-03-28T23:57:27.110143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Customers","metadata":{}},{"cell_type":"code","source":"customer_df = pd.read_csv(path+\"customers.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:27.111855Z","iopub.execute_input":"2022-03-28T23:57:27.112243Z","iopub.status.idle":"2022-03-28T23:57:32.577122Z","shell.execute_reply.started":"2022-03-28T23:57:27.112198Z","shell.execute_reply":"2022-03-28T23:57:32.576049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(customer_df.shape)\ncustomer_df.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:32.578432Z","iopub.execute_input":"2022-03-28T23:57:32.578741Z","iopub.status.idle":"2022-03-28T23:57:32.593166Z","shell.execute_reply.started":"2022-03-28T23:57:32.578709Z","shell.execute_reply":"2022-03-28T23:57:32.592567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:32.595487Z","iopub.execute_input":"2022-03-28T23:57:32.595887Z","iopub.status.idle":"2022-03-28T23:57:33.226484Z","shell.execute_reply.started":"2022-03-28T23:57:32.595844Z","shell.execute_reply":"2022-03-28T23:57:33.225513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"str_list = list(customer_df.columns)\nstr_list.remove('age')\nstr_list.remove('Active')\nfor col in str_list:\n    customer_df[col].fillna('Null', inplace = True)\n\ncustomer_df['Active'].fillna(0.0, inplace = True)\ncustomer_df['age'].fillna(0.0, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:33.228071Z","iopub.execute_input":"2022-03-28T23:57:33.228473Z","iopub.status.idle":"2022-03-28T23:57:34.072662Z","shell.execute_reply.started":"2022-03-28T23:57:33.228430Z","shell.execute_reply":"2022-03-28T23:57:34.071828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"var = 'Active'\nprint(len(customer_df[var].unique()))\nprint(customer_df[var].unique())","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:34.073849Z","iopub.execute_input":"2022-03-28T23:57:34.074214Z","iopub.status.idle":"2022-03-28T23:57:34.109716Z","shell.execute_reply.started":"2022-03-28T23:57:34.074184Z","shell.execute_reply":"2022-03-28T23:57:34.109008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.rcParams['font.size'] = 12\nplt.rcParams['text.color'] = 'white'\nplt.rcParams['axes.labelcolor'] = 'white'","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:34.111227Z","iopub.execute_input":"2022-03-28T23:57:34.111462Z","iopub.status.idle":"2022-03-28T23:57:34.115584Z","shell.execute_reply.started":"2022-03-28T23:57:34.111432Z","shell.execute_reply":"2022-03-28T23:57:34.115050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = customer_df['Active'].value_counts(sort = True).index\nactive_ = customer_df['Active'].value_counts(sort = True)\n\ncolors = [\"purple\", \"maroon\"]\nexplode = (0.1, 0)  # explode 1st slice\n \nrcParams['figure.figsize'] = 5, 5\n# Plot\nplt.pie(active_, explode=explode, labels=labels, colors=colors,\n        autopct='%1.1f%%', shadow=True, startangle=270,)\n\nplt.title('Distribution of Active Status of Customers',size = 14, color = 'white')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:34.116687Z","iopub.execute_input":"2022-03-28T23:57:34.117320Z","iopub.status.idle":"2022-03-28T23:57:34.298983Z","shell.execute_reply.started":"2022-03-28T23:57:34.117283Z","shell.execute_reply":"2022-03-28T23:57:34.298036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Observation: 66% of the customers in the data have inactive status assuming that NULL values in the data only represent inactivity and not missing value. Nevertheless, only 33% of the customers have active status.","metadata":{}},{"cell_type":"code","source":"plt.rcParams['text.color'] = 'black'\nplt.rcParams['axes.labelcolor'] = 'black'\nplt.rcParams['font.size'] = 10","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:34.300732Z","iopub.execute_input":"2022-03-28T23:57:34.301245Z","iopub.status.idle":"2022-03-28T23:57:34.306293Z","shell.execute_reply.started":"2022-03-28T23:57:34.301198Z","shell.execute_reply":"2022-03-28T23:57:34.305502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = customer_df['club_member_status'].value_counts(normalize=True).mul(100).round(1).plot(kind = 'bar',\n                                                                                        color = 'red', figsize = (8, 5),\n                                                                                        title = 'Bar graph of Club Member Status')\nax.set_xlabel(\"Club Member Status\", fontsize = 10)\nax.set_ylabel(\"Number of Customers\", fontsize = 10)\nplt.tick_params(labelsize = 10)\nplt.grid()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:34.307896Z","iopub.execute_input":"2022-03-28T23:57:34.308538Z","iopub.status.idle":"2022-03-28T23:57:34.751927Z","shell.execute_reply.started":"2022-03-28T23:57:34.308475Z","shell.execute_reply":"2022-03-28T23:57:34.751061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"80% of the customers have active membership status.\nI have yet to figure out how is this consistent with the above graph where \"active\" customers were just about 33%.","metadata":{}},{"cell_type":"code","source":"ax = customer_df['age'].hist(bins = 20, color = 'blue', figsize = (10, 5))\nax.set_title('Histogram for Age of Customers')\nax.set_xlabel('Age Bracket', fontsize = 10)\nax.set_ylabel('Number of Customers', fontsize = 10)\nplt.xticks(np.arange(min(customer_df['age']), max(customer_df['age'])+1, 5.0))\nplt.tick_params(labelsize = 10)\n#ax.grid()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:34.753168Z","iopub.execute_input":"2022-03-28T23:57:34.753360Z","iopub.status.idle":"2022-03-28T23:57:35.498221Z","shell.execute_reply.started":"2022-03-28T23:57:34.753336Z","shell.execute_reply":"2022-03-28T23:57:35.497341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This histogram shows that most of the customers in the data lie in the age group of 20-30 with the highest proportion in the age-group 20-25. There is also considerate proportion of customers in age group 45-55. Interestingly, we have customers below 5 years of age and above 70 years as well.","metadata":{}},{"cell_type":"code","source":"#del(ax)\n#del(customer_df)","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:35.499548Z","iopub.execute_input":"2022-03-28T23:57:35.499823Z","iopub.status.idle":"2022-03-28T23:57:35.503424Z","shell.execute_reply.started":"2022-03-28T23:57:35.499793Z","shell.execute_reply":"2022-03-28T23:57:35.502603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Transactions","metadata":{}},{"cell_type":"code","source":"trans_df = pd.read_csv(path+\"transactions_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:57:35.504734Z","iopub.execute_input":"2022-03-28T23:57:35.504942Z","iopub.status.idle":"2022-03-28T23:58:39.430525Z","shell.execute_reply.started":"2022-03-28T23:57:35.504918Z","shell.execute_reply":"2022-03-28T23:58:39.429745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(trans_df.shape)\ntrans_df.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:58:39.431833Z","iopub.execute_input":"2022-03-28T23:58:39.434526Z","iopub.status.idle":"2022-03-28T23:58:39.446774Z","shell.execute_reply.started":"2022-03-28T23:58:39.434484Z","shell.execute_reply":"2022-03-28T23:58:39.445894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:58:39.447872Z","iopub.execute_input":"2022-03-28T23:58:39.448095Z","iopub.status.idle":"2022-03-28T23:58:49.064809Z","shell.execute_reply.started":"2022-03-28T23:58:39.448067Z","shell.execute_reply":"2022-03-28T23:58:49.063992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.rcParams['font.size'] = 12\nplt.rcParams['text.color'] = 'white'\nplt.rcParams['axes.labelcolor'] = 'white'","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:58:49.066197Z","iopub.execute_input":"2022-03-28T23:58:49.066670Z","iopub.status.idle":"2022-03-28T23:58:49.073512Z","shell.execute_reply.started":"2022-03-28T23:58:49.066636Z","shell.execute_reply":"2022-03-28T23:58:49.072652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = trans_df['sales_channel_id'].value_counts(sort = True).index\ncounts_ = trans_df['sales_channel_id'].value_counts(sort = True)\n\ncolors = [\"blue\", \"maroon\"]\nexplode = (0.1, 0)  # explode 1st slice\n \nrcParams['figure.figsize'] = 5, 5\n# Plot\nplt.pie(counts_, explode=explode, labels=labels, colors=colors,\n        autopct='%1.1f%%', shadow=True, startangle=270,)\n\n\nplt.title('Distribution of Sales Channel ID in Transactions',size = 14, color = 'white')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:58:49.074923Z","iopub.execute_input":"2022-03-28T23:58:49.075148Z","iopub.status.idle":"2022-03-28T23:58:49.528811Z","shell.execute_reply.started":"2022-03-28T23:58:49.075120Z","shell.execute_reply":"2022-03-28T23:58:49.527700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"70% of transactions have been carried out through Sales Channel 2.","metadata":{}},{"cell_type":"code","source":"dates_trans = trans_df['t_dat'].str[:4]\nlabels = dates_trans.value_counts(sort = True).index\ncounts_ = dates_trans.value_counts(sort = True)\n\ncolors = ['purple', 'maroon', 'green']\nexplode = (0.1, 0.1, 0.)\n\nrcParams['figure.figsize'] = 5, 5\n# Plot\nplt.pie(counts_, explode=explode, labels=labels, colors=colors,\n        autopct='%1.1f%%', shadow=True, startangle=270,)\n\nplt.title('Percentage of transactions in years',size = 14, color = 'white')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:58:49.533987Z","iopub.execute_input":"2022-03-28T23:58:49.534491Z","iopub.status.idle":"2022-03-28T23:59:16.636049Z","shell.execute_reply.started":"2022-03-28T23:58:49.534442Z","shell.execute_reply":"2022-03-28T23:59:16.634806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"More than half of the transactions in the dataset took place in the year 2019, followed by 2020 and 2018. Only 13% of the transactions were recorded in 2018.","metadata":{}},{"cell_type":"code","source":"#del(trans_df)","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:59:16.637795Z","iopub.execute_input":"2022-03-28T23:59:16.638476Z","iopub.status.idle":"2022-03-28T23:59:16.644196Z","shell.execute_reply.started":"2022-03-28T23:59:16.638425Z","shell.execute_reply":"2022-03-28T23:59:16.642831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### How are transactions distributed across different age groups ?","metadata":{}},{"cell_type":"code","source":"trans_v_age = pd.merge(trans_df, customer_df[['customer_id', 'age']], on = 'customer_id', how = 'inner')","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:59:16.646111Z","iopub.execute_input":"2022-03-28T23:59:16.646790Z","iopub.status.idle":"2022-03-28T23:59:35.791192Z","shell.execute_reply.started":"2022-03-28T23:59:16.646738Z","shell.execute_reply":"2022-03-28T23:59:35.790305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.rcParams['text.color'] = 'black'\nplt.rcParams['axes.labelcolor'] = 'black'\nplt.rcParams['font.size'] = 10","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:59:35.792363Z","iopub.execute_input":"2022-03-28T23:59:35.792580Z","iopub.status.idle":"2022-03-28T23:59:35.797840Z","shell.execute_reply.started":"2022-03-28T23:59:35.792553Z","shell.execute_reply":"2022-03-28T23:59:35.796570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = trans_v_age['age'].hist(bins = 20, color = 'blue', figsize = (10, 5), weights=np.ones(len(trans_v_age)) / len(trans_v_age)*100)\nax.set_title('Age Distribution in Transactions')\nax.set_xlabel('Age Bracket', fontsize = 10)\nax.set_ylabel('Percentage % of Transactions', fontsize = 10)\nplt.xticks(np.arange(min(trans_v_age['age']), max(trans_v_age['age'])+1, 5.0))\nplt.tick_params(labelsize = 10)\n#ax.grid()","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:59:35.799116Z","iopub.execute_input":"2022-03-28T23:59:35.799342Z","iopub.status.idle":"2022-03-28T23:59:45.805432Z","shell.execute_reply.started":"2022-03-28T23:59:35.799316Z","shell.execute_reply":"2022-03-28T23:59:45.804485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del(trans_v_age)","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:59:45.806996Z","iopub.execute_input":"2022-03-28T23:59:45.807675Z","iopub.status.idle":"2022-03-28T23:59:46.244800Z","shell.execute_reply.started":"2022-03-28T23:59:45.807603Z","shell.execute_reply":"2022-03-28T23:59:46.243833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del(customer_df)","metadata":{"execution":{"iopub.status.busy":"2022-03-28T23:59:46.246371Z","iopub.execute_input":"2022-03-28T23:59:46.246719Z","iopub.status.idle":"2022-03-28T23:59:46.319298Z","shell.execute_reply.started":"2022-03-28T23:59:46.246677Z","shell.execute_reply":"2022-03-28T23:59:46.318354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"How consistent is this graph with the customer age distribution graph !!!","metadata":{}},{"cell_type":"markdown","source":"#### How are Product Section Name distributed across transactions ?","metadata":{}},{"cell_type":"code","source":"trans_v_article = pd.merge(trans_df, articles_df[['article_id', 'section_name']], on = 'article_id', how = 'inner')","metadata":{"execution":{"iopub.status.busy":"2022-03-29T00:00:41.829015Z","iopub.execute_input":"2022-03-29T00:00:41.829355Z","iopub.status.idle":"2022-03-29T00:01:01.856958Z","shell.execute_reply.started":"2022-03-29T00:00:41.829322Z","shell.execute_reply":"2022-03-29T00:01:01.855983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = trans_v_article['section_name'].value_counts(normalize=True).mul(100).round(1).plot(kind = 'bar',\n                                                                                        color = 'red', figsize = (16, 5),\n                                                                                        title = 'Bar graph of Product Section Name')\nax.set_xlabel(\"Product Section\", fontsize = 10)\nax.set_ylabel(\"Percentage of transactions\", fontsize = 10)\nplt.tick_params(labelsize = 10)\nplt.grid()\n#ax.grid()","metadata":{"execution":{"iopub.status.busy":"2022-03-29T00:05:53.218963Z","iopub.execute_input":"2022-03-29T00:05:53.219292Z","iopub.status.idle":"2022-03-29T00:05:59.227074Z","shell.execute_reply.started":"2022-03-29T00:05:53.219256Z","shell.execute_reply":"2022-03-29T00:05:59.226032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Women articles dominate in transaction records by a large margin ! ( I kinda expected it TBH)","metadata":{}},{"cell_type":"code","source":"del(trans_v_article)","metadata":{"execution":{"iopub.status.busy":"2022-03-29T00:20:43.876651Z","iopub.execute_input":"2022-03-29T00:20:43.877447Z","iopub.status.idle":"2022-03-29T00:20:45.356002Z","shell.execute_reply.started":"2022-03-29T00:20:43.877396Z","shell.execute_reply":"2022-03-29T00:20:45.354768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can do many such analysis. But I will leave it here for now.","metadata":{}},{"cell_type":"markdown","source":"### The End ","metadata":{}}]}