{"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":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-17T12:47:57.548470Z","iopub.execute_input":"2022-02-17T12:47:57.548936Z","iopub.status.idle":"2022-02-17T12:47:58.455158Z","shell.execute_reply.started":"2022-02-17T12:47:57.548828Z","shell.execute_reply":"2022-02-17T12:47:58.454481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_data = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv')\ncustomers_data = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')\nsubmission_data = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/sample_submission.csv')\ntrans_data = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-02-17T12:50:15.841317Z","iopub.execute_input":"2022-02-17T12:50:15.841570Z","iopub.status.idle":"2022-02-17T12:51:37.165097Z","shell.execute_reply.started":"2022-02-17T12:50:15.841544Z","shell.execute_reply":"2022-02-17T12:51:37.164064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Feature Engineering of Customer Data**\n> - Check club_member_status Data and take 'ACTIVE' Only \n> - Check Missing Value and Fill Missing Value of Age Data\n> - Convert type of Age from float64 to int64","metadata":{}},{"cell_type":"code","source":"customers_data['club_member_status'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T12:58:10.268983Z","iopub.execute_input":"2022-02-17T12:58:10.269279Z","iopub.status.idle":"2022-02-17T12:58:10.483967Z","shell.execute_reply.started":"2022-02-17T12:58:10.269250Z","shell.execute_reply":"2022-02-17T12:58:10.483069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_data_new = customers_data[(customers_data['club_member_status']=='ACTIVE')]","metadata":{"execution":{"iopub.status.busy":"2022-02-17T12:59:30.802665Z","iopub.execute_input":"2022-02-17T12:59:30.802929Z","iopub.status.idle":"2022-02-17T12:59:31.127069Z","shell.execute_reply.started":"2022-02-17T12:59:30.802902Z","shell.execute_reply":"2022-02-17T12:59:31.126310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_data_new.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:00:00.113408Z","iopub.execute_input":"2022-02-17T13:00:00.113695Z","iopub.status.idle":"2022-02-17T13:00:00.132870Z","shell.execute_reply.started":"2022-02-17T13:00:00.113665Z","shell.execute_reply":"2022-02-17T13:00:00.132376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> *Only need customer_id and age for Data Set of Customers_data_new*","metadata":{}},{"cell_type":"code","source":"customers_data_new.drop(labels=['FN','Active','club_member_status','fashion_news_frequency'],axis=1,inplace=True)\ncustomers_data_new.reset_index(drop=True, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:04:34.268381Z","iopub.execute_input":"2022-02-17T13:04:34.268627Z","iopub.status.idle":"2022-02-17T13:04:34.307978Z","shell.execute_reply.started":"2022-02-17T13:04:34.268600Z","shell.execute_reply":"2022-02-17T13:04:34.307364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_data_new.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:04:50.809981Z","iopub.execute_input":"2022-02-17T13:04:50.810996Z","iopub.status.idle":"2022-02-17T13:04:50.821998Z","shell.execute_reply.started":"2022-02-17T13:04:50.810933Z","shell.execute_reply":"2022-02-17T13:04:50.821187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_data_new.drop(labels=['postal_code'],axis=1,inplace=True)\ncustomers_data_new.reset_index(drop=True, inplace=True)\ncustomers_data_new.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:05:41.197584Z","iopub.execute_input":"2022-02-17T13:05:41.197883Z","iopub.status.idle":"2022-02-17T13:05:41.230619Z","shell.execute_reply.started":"2022-02-17T13:05:41.197833Z","shell.execute_reply":"2022-02-17T13:05:41.229721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"check memory usage of customers_data_new","metadata":{}},{"cell_type":"code","source":"customers_data_new.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:07:06.406987Z","iopub.execute_input":"2022-02-17T13:07:06.407640Z","iopub.status.idle":"2022-02-17T13:07:06.555525Z","shell.execute_reply.started":"2022-02-17T13:07:06.407610Z","shell.execute_reply":"2022-02-17T13:07:06.554310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Feature Engineering of Articles Data** \\\n> *Use Data prod_name, product_type_name and product_group_name for Attribute of EDA H&M Transaction of 2019*","metadata":{}},{"cell_type":"code","source":"articles_data.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:11:32.715345Z","iopub.execute_input":"2022-02-17T13:11:32.715579Z","iopub.status.idle":"2022-02-17T13:11:32.737056Z","shell.execute_reply.started":"2022-02-17T13:11:32.715556Z","shell.execute_reply":"2022-02-17T13:11:32.736647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_data[['prod_name','product_type_name','product_group_name']].describe()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:12:32.094186Z","iopub.execute_input":"2022-02-17T13:12:32.094495Z","iopub.status.idle":"2022-02-17T13:12:32.197662Z","shell.execute_reply.started":"2022-02-17T13:12:32.094475Z","shell.execute_reply":"2022-02-17T13:12:32.197116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_data_new = articles_data[['article_id','prod_name','product_type_name','product_group_name']].copy()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:07:50.501682Z","iopub.execute_input":"2022-02-17T15:07:50.502341Z","iopub.status.idle":"2022-02-17T15:07:50.512914Z","shell.execute_reply.started":"2022-02-17T15:07:50.502300Z","shell.execute_reply":"2022-02-17T15:07:50.512110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_data_new.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:07:52.861604Z","iopub.execute_input":"2022-02-17T15:07:52.861892Z","iopub.status.idle":"2022-02-17T15:07:52.873021Z","shell.execute_reply.started":"2022-02-17T15:07:52.861859Z","shell.execute_reply":"2022-02-17T15:07:52.872338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_data_new.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:07:56.175308Z","iopub.execute_input":"2022-02-17T15:07:56.175566Z","iopub.status.idle":"2022-02-17T15:07:56.214442Z","shell.execute_reply.started":"2022-02-17T15:07:56.175539Z","shell.execute_reply":"2022-02-17T15:07:56.213892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_data_new.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:07:58.992008Z","iopub.execute_input":"2022-02-17T15:07:58.992344Z","iopub.status.idle":"2022-02-17T15:07:59.012372Z","shell.execute_reply.started":"2022-02-17T15:07:58.992322Z","shell.execute_reply":"2022-02-17T15:07:59.011758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Feature Engineering of Transactional Data** \n> - *Drop or Exclude Data sales_channel_id of Attribute of EDA H&M Transaction of 2019*\n> - Build Date Extraction of t_dat (day (name) , month and year) for Attribute of EDA H&M Transaction of 2019\n> - Build New Column that is seasons of Transaction Purchases for Attribute of EDA H&M Transaction of 2019","metadata":{}},{"cell_type":"code","source":"trans_data.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:23:33.103326Z","iopub.execute_input":"2022-02-17T13:23:33.103543Z","iopub.status.idle":"2022-02-17T13:23:33.120400Z","shell.execute_reply.started":"2022-02-17T13:23:33.103520Z","shell.execute_reply":"2022-02-17T13:23:33.119649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_data['t_dat'] = trans_data['t_dat'].astype('datetime64')\ntrans_data.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:23:53.490460Z","iopub.execute_input":"2022-02-17T13:23:53.491375Z","iopub.status.idle":"2022-02-17T13:23:53.562919Z","shell.execute_reply.started":"2022-02-17T13:23:53.491342Z","shell.execute_reply":"2022-02-17T13:23:53.562333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_data['day_trans'] = trans_data['t_dat'].dt.day_name()\ntrans_data['month_trans'] = trans_data['t_dat'].dt.month\ntrans_data['year_trans'] = trans_data['t_dat'].dt.year","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:25:28.432273Z","iopub.execute_input":"2022-02-17T13:25:28.432477Z","iopub.status.idle":"2022-02-17T13:25:45.586381Z","shell.execute_reply.started":"2022-02-17T13:25:28.432456Z","shell.execute_reply":"2022-02-17T13:25:45.585615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ***Now I take Transaction Purchases of 2019 only for EDA and Prediction***","metadata":{}},{"cell_type":"code","source":"sample_trans_data = trans_data[(trans_data['year_trans']==2019)]","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:28:49.345352Z","iopub.execute_input":"2022-02-17T13:28:49.345612Z","iopub.status.idle":"2022-02-17T13:28:52.865413Z","shell.execute_reply.started":"2022-02-17T13:28:49.345585Z","shell.execute_reply":"2022-02-17T13:28:52.864795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_trans_data.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:29:14.449702Z","iopub.execute_input":"2022-02-17T13:29:14.450219Z","iopub.status.idle":"2022-02-17T13:29:17.784275Z","shell.execute_reply.started":"2022-02-17T13:29:14.450189Z","shell.execute_reply":"2022-02-17T13:29:17.783786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ***NOW, exlude or drop data t_dat and sales_channel_id from Dataset of Sample Data***","metadata":{}},{"cell_type":"code","source":"sample_trans_data.drop(labels=['t_dat','sales_channel_id'],axis=1,inplace=True)\nsample_trans_data.reset_index(drop=True,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:33:06.639010Z","iopub.execute_input":"2022-02-17T13:33:06.639449Z","iopub.status.idle":"2022-02-17T13:33:07.536283Z","shell.execute_reply.started":"2022-02-17T13:33:06.639413Z","shell.execute_reply":"2022-02-17T13:33:07.535554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_trans_data.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:33:29.044353Z","iopub.execute_input":"2022-02-17T13:33:29.044691Z","iopub.status.idle":"2022-02-17T13:33:30.246744Z","shell.execute_reply.started":"2022-02-17T13:33:29.044665Z","shell.execute_reply":"2022-02-17T13:33:30.246086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_trans_data.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:33:47.462000Z","iopub.execute_input":"2022-02-17T13:33:47.462249Z","iopub.status.idle":"2022-02-17T13:33:47.471745Z","shell.execute_reply.started":"2022-02-17T13:33:47.462216Z","shell.execute_reply":"2022-02-17T13:33:47.470986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_trans_data.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:33:59.669546Z","iopub.execute_input":"2022-02-17T13:33:59.670437Z","iopub.status.idle":"2022-02-17T13:33:59.682167Z","shell.execute_reply.started":"2022-02-17T13:33:59.670406Z","shell.execute_reply":"2022-02-17T13:33:59.681243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ***AND NOW, Build EDA of Data Customers***","metadata":{}},{"cell_type":"code","source":"sns.set_style('whitegrid')\ncustomers_data_new['age'].plot(kind='hist')","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:37:26.815832Z","iopub.execute_input":"2022-02-17T13:37:26.816738Z","iopub.status.idle":"2022-02-17T13:37:28.061756Z","shell.execute_reply.started":"2022-02-17T13:37:26.816682Z","shell.execute_reply":"2022-02-17T13:37:28.060938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> *Build and New Attribute that is **Interval of Age Data** for Next EDA of Customers Data of H&M Transaction*","metadata":{}},{"cell_type":"code","source":"interval_range_age = pd.interval_range(start=0, freq=10, end=100)\ncustomers_data_new['age_group'] = pd.cut(customers_data_new['age'],bins=interval_range_age)\ncustomers_data_new.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:40:16.692688Z","iopub.execute_input":"2022-02-17T13:40:16.692968Z","iopub.status.idle":"2022-02-17T13:40:18.505494Z","shell.execute_reply.started":"2022-02-17T13:40:16.692940Z","shell.execute_reply":"2022-02-17T13:40:18.504800Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_data_new.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:41:39.226302Z","iopub.execute_input":"2022-02-17T13:41:39.226524Z","iopub.status.idle":"2022-02-17T13:41:39.288707Z","shell.execute_reply.started":"2022-02-17T13:41:39.226504Z","shell.execute_reply":"2022-02-17T13:41:39.287831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ***Lets combine Data Transaction Purchases of 2019 and Data Customers for EDA Customer Transcation Purchases of 2019***","metadata":{}},{"cell_type":"code","source":"purchases_2019 = sample_trans_data.merge(customers_data_new, how='left', on='customer_id')","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:44:57.640270Z","iopub.execute_input":"2022-02-17T13:44:57.640496Z","iopub.status.idle":"2022-02-17T13:45:07.453749Z","shell.execute_reply.started":"2022-02-17T13:44:57.640474Z","shell.execute_reply":"2022-02-17T13:45:07.453023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_temp = purchases_2019.groupby(['age_group'])['customer_id'].count()\ndata_temp_customer = pd.DataFrame({\n    'Group Age' : customers_temp.index,\n    'Customers' : customers_temp.values\n})\ndata_temp_customer = data_temp_customer.sort_values(['Group Age'],ascending=False)\nplt.figure(figsize=(7,7))\nplt.title(f'Group Age')\nsns.set_color_codes('pastel')\ns = sns.barplot(x='Group Age', y='Customers', data=data_temp_customer)\ns.set_xticklabels(s.get_xticklabels(),rotation=45)\nlocs, labels = plt.xticks()\nplt.show","metadata":{"execution":{"iopub.status.busy":"2022-02-17T13:53:39.385145Z","iopub.execute_input":"2022-02-17T13:53:39.385581Z","iopub.status.idle":"2022-02-17T13:53:41.403584Z","shell.execute_reply.started":"2022-02-17T13:53:39.385552Z","shell.execute_reply":"2022-02-17T13:53:41.402781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ***Take of Most Age Group of Customers that is (20,30] for EDA day and Seasons Transaction***","metadata":{}},{"cell_type":"code","source":"#day transaction of Most Age Group of Customers\nmost_age_group_transaction = purchases_2019[(purchases_2019['age_group']==purchases_2019['age_group'].mode()[0])]\ncustomers_temp_most = most_age_group_transaction.groupby(['day_trans'])['customer_id'].count()\ndata_temp_customer_most = pd.DataFrame({\n    'Day Transaction' : customers_temp_most.index,\n    'Customers' : customers_temp_most.values\n})\ndata_temp_customer_most = data_temp_customer_most.sort_values(['Customers'],ascending=False)\nplt.figure(figsize=(7,7))\nplt.title(f'Day Transaction of Most Age Group Customers')\nsns.set_color_codes('pastel')\ns = sns.barplot(x='Day Transaction', y='Customers', data=data_temp_customer_most)\ns.set_xticklabels(s.get_xticklabels())\nlocs, labels = plt.xticks()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T14:46:43.132190Z","iopub.execute_input":"2022-02-17T14:46:43.132457Z","iopub.status.idle":"2022-02-17T14:46:45.723010Z","shell.execute_reply.started":"2022-02-17T14:46:43.132429Z","shell.execute_reply":"2022-02-17T14:46:45.722510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> *Build and New Attribute that is **Seasons of Transaction** for Next EDA of Customers Data of H&M Transaction*","metadata":{}},{"cell_type":"code","source":"#New Attribute - Column Seasons\nbins = [0,3,6,9,12] #numbers of month on one year\nlabels = ['Winter','Spring','Summer','Autumn']\npurchases_2019['Seasons'] = pd.cut(purchases_2019['month_trans'], bins=bins, labels=labels)\npurchases_2019.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T14:54:59.926875Z","iopub.execute_input":"2022-02-17T14:54:59.927127Z","iopub.status.idle":"2022-02-17T14:55:00.159307Z","shell.execute_reply.started":"2022-02-17T14:54:59.927100Z","shell.execute_reply":"2022-02-17T14:55:00.158474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#seasons transaction of Most Age Group of Customers\nmost_age_group_transaction = purchases_2019[(purchases_2019['age_group']==purchases_2019['age_group'].mode()[0])]\ncustomers_temp_most = most_age_group_transaction.groupby(['Seasons'])['customer_id'].count()\ndata_temp_customer_most = pd.DataFrame({\n    'Seasons Transaction' : customers_temp_most.index,\n    'Customers' : customers_temp_most.values\n})\ndata_temp_customer_most = data_temp_customer_most.sort_values(['Customers'],ascending=False)\nplt.figure(figsize=(7,7))\nplt.title(f'Seasons Transaction of Most Age Group Customers')\nsns.set_color_codes('pastel')\ns = sns.barplot(x='Seasons Transaction', y='Customers', data=data_temp_customer_most)\ns.set_xticklabels(s.get_xticklabels())\nlocs, labels = plt.xticks()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T14:57:27.330724Z","iopub.execute_input":"2022-02-17T14:57:27.330962Z","iopub.status.idle":"2022-02-17T14:57:29.183127Z","shell.execute_reply.started":"2022-02-17T14:57:27.330939Z","shell.execute_reply":"2022-02-17T14:57:29.182614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **EDA of Customer attribute is done**, \\\n> This conclusion:\n> ","metadata":{}},{"cell_type":"markdown","source":"> ***Lets combine Data Transaction Purchases of 2019 + Data Customers and Articles Data for EDA Articles Transcation Purchases of 2019***","metadata":{}},{"cell_type":"code","source":"purchases_2019.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:01:11.297500Z","iopub.execute_input":"2022-02-17T15:01:11.297746Z","iopub.status.idle":"2022-02-17T15:01:11.313353Z","shell.execute_reply.started":"2022-02-17T15:01:11.297720Z","shell.execute_reply":"2022-02-17T15:01:11.312894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> *exclude or drop column price and age, because this attribute is not used for EDA Article Transaction and to reduce memory usege of processing the data*","metadata":{}},{"cell_type":"code","source":"purchases_2019.drop(labels=['price','age'],axis=1,inplace=True)\npurchases_2019.reset_index(drop=True,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:04:02.528385Z","iopub.execute_input":"2022-02-17T15:04:02.528761Z","iopub.status.idle":"2022-02-17T15:04:02.992226Z","shell.execute_reply.started":"2022-02-17T15:04:02.528724Z","shell.execute_reply":"2022-02-17T15:04:02.991482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"purchases_2019.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:04:25.421207Z","iopub.execute_input":"2022-02-17T15:04:25.421471Z","iopub.status.idle":"2022-02-17T15:04:25.436431Z","shell.execute_reply.started":"2022-02-17T15:04:25.421442Z","shell.execute_reply":"2022-02-17T15:04:25.435868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#combine Data with df.merge\npurchases_2019 = purchases_2019.merge(articles_data_new, how='left',on='article_id')","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:08:40.579589Z","iopub.execute_input":"2022-02-17T15:08:40.580394Z","iopub.status.idle":"2022-02-17T15:08:45.735332Z","shell.execute_reply.started":"2022-02-17T15:08:40.580363Z","shell.execute_reply":"2022-02-17T15:08:45.734653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"purchases_2019.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:08:57.925034Z","iopub.execute_input":"2022-02-17T15:08:57.925832Z","iopub.status.idle":"2022-02-17T15:08:57.942070Z","shell.execute_reply.started":"2022-02-17T15:08:57.925800Z","shell.execute_reply":"2022-02-17T15:08:57.941252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#prod_name\narticles_temp_data  = purchases_2019.groupby(['prod_name'])['customer_id'].count()\ndata_temp_articles = pd.DataFrame({\n    'Product Name' : articles_temp_data.index,\n    'Customers' : articles_temp_data.values\n})\ndata_temp_articles = data_temp_articles.sort_values(['Customers'],ascending=False)[:15]\nplt.figure(figsize=(7,7))\nplt.title(f'Top 15 Product Name in 2019 Transaction')\nsns.set_color_codes('pastel')\ns = sns.barplot(x='Product Name',y='Customers',data=data_temp_articles)\ns.set_xticklabels(s.get_xticklabels(),rotation=90)\nlocs, labels = plt.xticks()\nplt.show\n","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:35:50.678970Z","iopub.execute_input":"2022-02-17T15:35:50.679237Z","iopub.status.idle":"2022-02-17T15:35:56.196603Z","shell.execute_reply.started":"2022-02-17T15:35:50.679209Z","shell.execute_reply":"2022-02-17T15:35:56.195853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#product_type_name\narticles_temp_data  = purchases_2019.groupby(['product_type_name'])['customer_id'].count()\ndata_temp_articles = pd.DataFrame({\n    'Product Type' : articles_temp_data.index,\n    'Customers' : articles_temp_data.values\n})\ndata_temp_articles = data_temp_articles.sort_values(['Customers'],ascending=False)[:15]\nplt.figure(figsize=(7,7))\nplt.title(f'Top 15 Product Type in 2019 Transaction')\nsns.set_color_codes('pastel')\ns = sns.barplot(x='Product Type',y='Customers',data=data_temp_articles)\ns.set_xticklabels(s.get_xticklabels(),rotation=90)\nlocs, labels = plt.xticks()\nplt.show","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:37:41.564108Z","iopub.execute_input":"2022-02-17T15:37:41.564373Z","iopub.status.idle":"2022-02-17T15:37:44.333008Z","shell.execute_reply.started":"2022-02-17T15:37:41.564345Z","shell.execute_reply":"2022-02-17T15:37:44.332303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#product_group_name\narticles_temp_data  = purchases_2019.groupby(['product_group_name'])['customer_id'].count()\ndata_temp_articles = pd.DataFrame({\n    'Product Group' : articles_temp_data.index,\n    'Customers' : articles_temp_data.values\n})\ndata_temp_articles = data_temp_articles.sort_values(['Customers'],ascending=False)[:15]\nplt.figure(figsize=(7,7))\nplt.title(f'Top 15 Product Group in 2019 Transaction')\nsns.set_color_codes('pastel')\ns = sns.barplot(x='Product Group',y='Customers',data=data_temp_articles)\ns.set_xticklabels(s.get_xticklabels(),rotation=90)\nlocs, labels = plt.xticks()\nplt.show","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:39:59.955857Z","iopub.execute_input":"2022-02-17T15:39:59.956132Z","iopub.status.idle":"2022-02-17T15:40:02.343134Z","shell.execute_reply.started":"2022-02-17T15:39:59.956101Z","shell.execute_reply":"2022-02-17T15:40:02.342571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"purchases_2019.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T15:40:55.137690Z","iopub.execute_input":"2022-02-17T15:40:55.137942Z","iopub.status.idle":"2022-02-17T15:40:55.153544Z","shell.execute_reply.started":"2022-02-17T15:40:55.137917Z","shell.execute_reply":"2022-02-17T15:40:55.153091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#PREDICTION ","metadata":{},"execution_count":null,"outputs":[]}]}