{"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":"# Author: Lea Kotler\n# Date: 9 July 2023\n\nimport numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-07-10T13:26:33.414162Z","iopub.execute_input":"2023-07-10T13:26:33.414746Z","iopub.status.idle":"2023-07-10T13:26:34.432575Z","shell.execute_reply.started":"2023-07-10T13:26:33.414704Z","shell.execute_reply":"2023-07-10T13:26:34.431687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/articles.csv\")\ncustomers = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/customers.csv\")\ntransactions = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:26:34.434476Z","iopub.execute_input":"2023-07-10T13:26:34.435499Z","iopub.status.idle":"2023-07-10T13:27:55.960790Z","shell.execute_reply.started":"2023-07-10T13:26:34.435453Z","shell.execute_reply":"2023-07-10T13:27:55.959772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:55.985412Z","iopub.execute_input":"2023-07-10T13:27:55.986414Z","iopub.status.idle":"2023-07-10T13:27:56.035059Z","shell.execute_reply.started":"2023-07-10T13:27:55.986379Z","shell.execute_reply":"2023-07-10T13:27:56.034084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Articles**\n* article_id : A unique identifier of every article.\n* product_code, prod_name : A unique identifier of every product and its name\n* product_type, product_type_name : The group of product_code and its name\n* graphical_appearance_no, graphical_appearance_name : The group of graphics and its name\n* colour_group_code, colour_group_name : The group of color and its name\n* perceived_colour_value_id, perceived_colour_value_name, perceived_colour_master_id, perceived_colour_master_name : The added color info\n* department_no, department_name: : A unique identifier of every dep and its name\n* index_code, index_name: : A unique identifier of every index and its name\n* index_group_no, index_group_name: : A group of indices and its name\n* section_no, section_name: : A unique identifier of every section and its name\n* garment_group_no, garment_group_name: : A unique identifier of every garment and its name\n* detail_desc: : Details","metadata":{}},{"cell_type":"markdown","source":"How many unique row in every column","metadata":{}},{"cell_type":"code","source":"for col in articles.columns:\n    if not 'no' in col and not 'code' in col and not 'id' in col:\n        un_n = articles[col].nunique()\n        print(f'no of unique {col}: {un_n}')","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:56.037395Z","iopub.execute_input":"2023-07-10T13:27:56.038498Z","iopub.status.idle":"2023-07-10T13:27:56.210882Z","shell.execute_reply.started":"2023-07-10T13:27:56.038449Z","shell.execute_reply":"2023-07-10T13:27:56.209680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Analysis of index_name","metadata":{}},{"cell_type":"code","source":"articles['index_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:56.212313Z","iopub.execute_input":"2023-07-10T13:27:56.213085Z","iopub.status.idle":"2023-07-10T13:27:56.242396Z","shell.execute_reply.started":"2023-07-10T13:27:56.213053Z","shell.execute_reply":"2023-07-10T13:27:56.241131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15,7))\nax = sns.histplot(data=articles, y='index_name')\nax.set_xlabel('count by index name')\nax.set_ylabel('index name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:56.243979Z","iopub.execute_input":"2023-07-10T13:27:56.244491Z","iopub.status.idle":"2023-07-10T13:27:56.896674Z","shell.execute_reply.started":"2023-07-10T13:27:56.244457Z","shell.execute_reply":"2023-07-10T13:27:56.895419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Analysis of index_group_name depending on garment_group_name","metadata":{}},{"cell_type":"code","source":"articles[['garment_group_name','index_group_name']].head()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:56.898310Z","iopub.execute_input":"2023-07-10T13:27:56.898753Z","iopub.status.idle":"2023-07-10T13:27:56.913834Z","shell.execute_reply.started":"2023-07-10T13:27:56.898715Z","shell.execute_reply":"2023-07-10T13:27:56.912508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15,7))\nax = sns.histplot(data=articles, y='garment_group_name', hue='index_group_name',multiple='stack')\nax.set_xlabel('count by garment group')\nax.set_ylabel('garment group')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:56.915749Z","iopub.execute_input":"2023-07-10T13:27:56.916167Z","iopub.status.idle":"2023-07-10T13:27:58.248932Z","shell.execute_reply.started":"2023-07-10T13:27:56.916135Z","shell.execute_reply":"2023-07-10T13:27:58.248023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"jersey_fancy is the most popular,also accesosories is very popular. a cpecially for women and babies.","metadata":{}},{"cell_type":"markdown","source":"subcategory from index_group_name and quintity of items in it","metadata":{}},{"cell_type":"code","source":"articles.groupby(['index_group_name','index_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:58.250304Z","iopub.execute_input":"2023-07-10T13:27:58.250860Z","iopub.status.idle":"2023-07-10T13:27:58.690229Z","shell.execute_reply.started":"2023-07-10T13:27:58.250829Z","shell.execute_reply":"2023-07-10T13:27:58.689420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"types of items by category","metadata":{}},{"cell_type":"code","source":"pd.options.display.max_rows = None\narticles.groupby(['product_group_name', 'product_type_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:58.694301Z","iopub.execute_input":"2023-07-10T13:27:58.694901Z","iopub.status.idle":"2023-07-10T13:27:59.137580Z","shell.execute_reply.started":"2023-07-10T13:27:58.694867Z","shell.execute_reply":"2023-07-10T13:27:59.136331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Top 10 types of items","metadata":{}},{"cell_type":"code","source":"top_ten = articles.groupby(['product_type_name']).count()['article_id'].sort_values(ascending=False).iloc[:10]\ntop_ten","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:59.139088Z","iopub.execute_input":"2023-07-10T13:27:59.139440Z","iopub.status.idle":"2023-07-10T13:27:59.596161Z","shell.execute_reply.started":"2023-07-10T13:27:59.139412Z","shell.execute_reply":"2023-07-10T13:27:59.594915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15,7))\nax = sns.barplot(x=top_ten.index, y=top_ten.values)\nax.set_xlabel('count by type name')\nax.set_ylabel('type name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:59.597788Z","iopub.execute_input":"2023-07-10T13:27:59.598171Z","iopub.status.idle":"2023-07-10T13:27:59.931433Z","shell.execute_reply.started":"2023-07-10T13:27:59.598142Z","shell.execute_reply":"2023-07-10T13:27:59.930295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Top 10 categories","metadata":{}},{"cell_type":"code","source":"top_group = articles.groupby(['product_group_name']).count()['article_id'].sort_values(ascending=False).iloc[:10]\ntop_group","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:27:59.932947Z","iopub.execute_input":"2023-07-10T13:27:59.933432Z","iopub.status.idle":"2023-07-10T13:28:00.402204Z","shell.execute_reply.started":"2023-07-10T13:27:59.933399Z","shell.execute_reply":"2023-07-10T13:28:00.400787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15,7))\nax = sns.barplot(x=top_group.index, y=top_group.values)\nax.set_xlabel('count by group name')\nax.set_ylabel('group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:00.403931Z","iopub.execute_input":"2023-07-10T13:28:00.404982Z","iopub.status.idle":"2023-07-10T13:28:00.763044Z","shell.execute_reply.started":"2023-07-10T13:28:00.404943Z","shell.execute_reply":"2023-07-10T13:28:00.761758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Top 10 graphical appearance name","metadata":{}},{"cell_type":"code","source":"top_graph = articles.groupby(['graphical_appearance_name']).count()['article_id'].sort_values(ascending=False).iloc[:10]\ntop_graph","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:00.764437Z","iopub.execute_input":"2023-07-10T13:28:00.764772Z","iopub.status.idle":"2023-07-10T13:28:01.249161Z","shell.execute_reply.started":"2023-07-10T13:28:00.764746Z","shell.execute_reply":"2023-07-10T13:28:01.248089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15,7))\nax = sns.barplot(x=top_graph.index, y=top_graph.values)\nax.set_xlabel('count by graphical appearance name')\nax.set_ylabel('graphical appearance name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:01.250947Z","iopub.execute_input":"2023-07-10T13:28:01.251675Z","iopub.status.idle":"2023-07-10T13:28:01.543548Z","shell.execute_reply.started":"2023-07-10T13:28:01.251634Z","shell.execute_reply":"2023-07-10T13:28:01.542341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Top colors","metadata":{}},{"cell_type":"code","source":"top_color = articles.groupby(['colour_group_name']).count()['article_id'].sort_values(ascending=False).iloc[:10]\ntop_color","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:01.545122Z","iopub.execute_input":"2023-07-10T13:28:01.545533Z","iopub.status.idle":"2023-07-10T13:28:02.008706Z","shell.execute_reply.started":"2023-07-10T13:28:01.545502Z","shell.execute_reply":"2023-07-10T13:28:02.007339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15,7))\nax = sns.barplot(x=top_color.index, y=top_color.values)\nax.set_xlabel('count by color group name')\nax.set_ylabel('color group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:02.010158Z","iopub.execute_input":"2023-07-10T13:28:02.010652Z","iopub.status.idle":"2023-07-10T13:28:02.336340Z","shell.execute_reply.started":"2023-07-10T13:28:02.010611Z","shell.execute_reply":"2023-07-10T13:28:02.335174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Customers**","metadata":{}},{"cell_type":"code","source":"pd.options.display.max_rows = 50\ncustomers.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:02.337897Z","iopub.execute_input":"2023-07-10T13:28:02.338399Z","iopub.status.idle":"2023-07-10T13:28:02.361064Z","shell.execute_reply.started":"2023-07-10T13:28:02.338365Z","shell.execute_reply":"2023-07-10T13:28:02.359927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Customers data description\n* customer_id : A unique identifier of every customer\n* FN : 1 or missed (not clear what it is)\n* Active : 1 or missed (need to check if it is linked to making purchases)\n* club_member_status : Status in club\n* fashion_news_frequency : How often H&M may send news to customer\n* age : The current age\n* postal_code : Postal code of customer","metadata":{}},{"cell_type":"markdown","source":"Checking if there are not duplicates of clients ","metadata":{}},{"cell_type":"code","source":"customers.shape[0] - customers['customer_id'].nunique()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:02.363082Z","iopub.execute_input":"2023-07-10T13:28:02.364044Z","iopub.status.idle":"2023-07-10T13:28:03.153974Z","shell.execute_reply.started":"2023-07-10T13:28:02.363997Z","shell.execute_reply":"2023-07-10T13:28:03.152579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_postal = customers.groupby('postal_code', as_index=False).count().sort_values('customer_id', ascending=False)\ndata_postal.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:03.155417Z","iopub.execute_input":"2023-07-10T13:28:03.155771Z","iopub.status.idle":"2023-07-10T13:28:06.141551Z","shell.execute_reply.started":"2023-07-10T13:28:03.155743Z","shell.execute_reply":"2023-07-10T13:28:06.140472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There is postal_code with anomaly big number of customers","metadata":{}},{"cell_type":"code","source":"data_postal['postal_code'].iloc[0]","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:06.142784Z","iopub.execute_input":"2023-07-10T13:28:06.143204Z","iopub.status.idle":"2023-07-10T13:28:06.150025Z","shell.execute_reply.started":"2023-07-10T13:28:06.143177Z","shell.execute_reply":"2023-07-10T13:28:06.149036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers[customers['postal_code'] == '2c29ae653a9282cce4151bd87643c907644e09541abc28ae87dea0d1f6603b1c'].head(5)","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:06.151729Z","iopub.execute_input":"2023-07-10T13:28:06.152192Z","iopub.status.idle":"2023-07-10T13:28:06.469125Z","shell.execute_reply.started":"2023-07-10T13:28:06.152160Z","shell.execute_reply":"2023-07-10T13:28:06.468032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Different client choose postal_code = 2c29ae653a9282cce4151bd87643c907644e09541abc28ae87dea0d1f6603b1c","metadata":{}},{"cell_type":"markdown","source":"Ages of clients","metadata":{}},{"cell_type":"code","source":"sns.set_style('darkgrid')\nf, ax = plt.subplots(figsize = (10,5))\nax = sns.histplot(data=customers, x='age', bins=50)\nax.set_xlabel('Distribution of the customers age')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:06.470489Z","iopub.execute_input":"2023-07-10T13:28:06.470884Z","iopub.status.idle":"2023-07-10T13:28:07.855800Z","shell.execute_reply.started":"2023-07-10T13:28:06.470857Z","shell.execute_reply":"2023-07-10T13:28:07.854696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Club member status","metadata":{}},{"cell_type":"code","source":"sns.set_style('darkgrid')\nf, ax = plt.subplots(figsize = (10,5))\nax = sns.histplot(data=customers, x='club_member_status')\nax.set_xlabel('Distribution of the club status')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:07.857493Z","iopub.execute_input":"2023-07-10T13:28:07.857935Z","iopub.status.idle":"2023-07-10T13:28:11.534417Z","shell.execute_reply.started":"2023-07-10T13:28:07.857893Z","shell.execute_reply":"2023-07-10T13:28:11.533189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Analyze of news frequency","metadata":{}},{"cell_type":"code","source":"customers['fashion_news_frequency'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:11.535884Z","iopub.execute_input":"2023-07-10T13:28:11.536223Z","iopub.status.idle":"2023-07-10T13:28:11.694922Z","shell.execute_reply.started":"2023-07-10T13:28:11.536196Z","shell.execute_reply":"2023-07-10T13:28:11.693682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.loc[~customers['fashion_news_frequency'].isin(['Regularly', 'Monthly']),'fashion_news_frequency'] = 'None'\ncustomers['fashion_news_frequency'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:11.696556Z","iopub.execute_input":"2023-07-10T13:28:11.696989Z","iopub.status.idle":"2023-07-10T13:28:11.917890Z","shell.execute_reply.started":"2023-07-10T13:28:11.696957Z","shell.execute_reply":"2023-07-10T13:28:11.916730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pie_data = customers[['customer_id','fashion_news_frequency']].groupby('fashion_news_frequency').count()\npie_data","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:11.925391Z","iopub.execute_input":"2023-07-10T13:28:11.926189Z","iopub.status.idle":"2023-07-10T13:28:12.558479Z","shell.execute_reply.started":"2023-07-10T13:28:11.926145Z","shell.execute_reply":"2023-07-10T13:28:12.557348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid')\nf, ax = plt.subplots(figsize = (10,5))\nax.pie(pie_data.customer_id, labels=pie_data.index)\nax.set_xlabel('Distribution of fashion news frequency')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:12.560424Z","iopub.execute_input":"2023-07-10T13:28:12.561302Z","iopub.status.idle":"2023-07-10T13:28:12.717033Z","shell.execute_reply.started":"2023-07-10T13:28:12.561235Z","shell.execute_reply":"2023-07-10T13:28:12.715384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most number of clients do not want to get news","metadata":{}},{"cell_type":"markdown","source":"**Transactions**","metadata":{}},{"cell_type":"code","source":"transactions.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:12.719960Z","iopub.execute_input":"2023-07-10T13:28:12.720758Z","iopub.status.idle":"2023-07-10T13:28:12.746997Z","shell.execute_reply.started":"2023-07-10T13:28:12.720694Z","shell.execute_reply":"2023-07-10T13:28:12.744698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Transactions data description:\n\n* t_dat : Purchase date\n* customer_id : A unique identifier of every customer (in customers table)\n* article_id : A unique identifier of every article (in articles table)\n* price : Price of purchase\n* sales_channel_id : 1 or 2","metadata":{}},{"cell_type":"markdown","source":"Outliers price","metadata":{}},{"cell_type":"code","source":"pd.set_option('display.float_format', '{:.4f}'.format)\ntransactions.describe()['price']","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:12.750689Z","iopub.execute_input":"2023-07-10T13:28:12.752364Z","iopub.status.idle":"2023-07-10T13:28:16.275514Z","shell.execute_reply.started":"2023-07-10T13:28:12.752283Z","shell.execute_reply":"2023-07-10T13:28:16.274465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid')\nf, ax = plt.subplots(figsize = (10,5))\nax = sns.boxplot(data=transactions, x='price')\nax.set_xlabel('Price outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:16.276915Z","iopub.execute_input":"2023-07-10T13:28:16.277326Z","iopub.status.idle":"2023-07-10T13:28:20.615448Z","shell.execute_reply.started":"2023-07-10T13:28:16.277297Z","shell.execute_reply":"2023-07-10T13:28:20.614005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"customers who frequently buy","metadata":{}},{"cell_type":"code","source":"transactions_byid = transactions.groupby('customer_id').count()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:20.616939Z","iopub.execute_input":"2023-07-10T13:28:20.618046Z","iopub.status.idle":"2023-07-10T13:28:44.895471Z","shell.execute_reply.started":"2023-07-10T13:28:20.618008Z","shell.execute_reply":"2023-07-10T13:28:44.893961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_byid.sort_values(by='price', ascending=False)['price'][:10]","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:44.897122Z","iopub.execute_input":"2023-07-10T13:28:44.897771Z","iopub.status.idle":"2023-07-10T13:28:45.362667Z","shell.execute_reply.started":"2023-07-10T13:28:44.897735Z","shell.execute_reply":"2023-07-10T13:28:45.361558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Merging 2 tables: Articles and transactions","metadata":{}},{"cell_type":"code","source":"articles_for_merge = articles[['article_id','prod_name','product_type_name','product_group_name','index_name']]\narticles_for_merge.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:45.364533Z","iopub.execute_input":"2023-07-10T13:28:45.364898Z","iopub.status.idle":"2023-07-10T13:28:45.384742Z","shell.execute_reply.started":"2023-07-10T13:28:45.364867Z","shell.execute_reply":"2023-07-10T13:28:45.383504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_for_merge = transactions[['customer_id','article_id','price','t_dat']].merge(articles_for_merge,on='article_id')\narticles_for_merge","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:28:45.386659Z","iopub.execute_input":"2023-07-10T13:28:45.387154Z","iopub.status.idle":"2023-07-10T13:29:05.949144Z","shell.execute_reply.started":"2023-07-10T13:28:45.387112Z","shell.execute_reply":"2023-07-10T13:29:05.948016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid')\nf, ax = plt.subplots(figsize = (25,18))\nax = sns.boxplot(data=articles_for_merge, x='price', y='product_group_name')\nax.set_xlabel('Price outliers',fontsize=22)\nax.set_ylabel('Index names',fontsize=22)\nax.xaxis.set_tick_params(labelsize=22)\nax.yaxis.set_tick_params(labelsize=22)\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:29:05.950733Z","iopub.execute_input":"2023-07-10T13:29:05.951967Z","iopub.status.idle":"2023-07-10T13:29:36.721381Z","shell.execute_reply.started":"2023-07-10T13:29:05.951916Z","shell.execute_reply":"2023-07-10T13:29:36.720033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accessories = articles_for_merge[articles_for_merge['product_group_name'] == 'Accessories']\naccessories.head()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:29:36.723672Z","iopub.execute_input":"2023-07-10T13:29:36.724641Z","iopub.status.idle":"2023-07-10T13:29:51.766431Z","shell.execute_reply.started":"2023-07-10T13:29:36.724591Z","shell.execute_reply":"2023-07-10T13:29:51.765265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid')\nf, ax = plt.subplots(figsize = (20,18))\nax = sns.boxplot(data=accessories, x='price', y='product_type_name')\nax.set_xlabel('Price outliers',fontsize=22)\nax.set_ylabel('Index names',fontsize=22)\nax.xaxis.set_tick_params(labelsize=22)\nax.yaxis.set_tick_params(labelsize=22)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:29:51.768011Z","iopub.execute_input":"2023-07-10T13:29:51.768489Z","iopub.status.idle":"2023-07-10T13:29:54.384621Z","shell.execute_reply.started":"2023-07-10T13:29:51.768456Z","shell.execute_reply":"2023-07-10T13:29:54.383360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Mean price by category","metadata":{}},{"cell_type":"code","source":"articles_index = articles_for_merge[['index_name','price']].groupby('index_name').mean()\narticles_index = articles_index.sort_values('price')\narticles_index","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:29:54.386094Z","iopub.execute_input":"2023-07-10T13:29:54.386489Z","iopub.status.idle":"2023-07-10T13:29:58.735442Z","shell.execute_reply.started":"2023-07-10T13:29:54.386457Z","shell.execute_reply":"2023-07-10T13:29:58.734207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The most excpensive items are in Ladieswear, the most chippest in Baby Sizes","metadata":{}},{"cell_type":"code","source":"sns.set_style('darkgrid')\nf, ax = plt.subplots(figsize = (20,18))\nax = sns.barplot( x=articles_index.price, y=articles_index.index)\nax.set_xlabel('Price by index',fontsize=22)\nax.set_ylabel('Index',fontsize=32)\nax.xaxis.set_tick_params(labelsize=22)\nax.yaxis.set_tick_params(labelsize=22)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:29:58.736846Z","iopub.execute_input":"2023-07-10T13:29:58.737222Z","iopub.status.idle":"2023-07-10T13:29:59.397181Z","shell.execute_reply.started":"2023-07-10T13:29:58.737191Z","shell.execute_reply":"2023-07-10T13:29:59.396227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_index = articles_for_merge[['product_group_name','price']].groupby('product_group_name').mean()\narticles_index = articles_index.sort_values('price')\narticles_index","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:29:59.398699Z","iopub.execute_input":"2023-07-10T13:29:59.399825Z","iopub.status.idle":"2023-07-10T13:30:03.982360Z","shell.execute_reply.started":"2023-07-10T13:29:59.399787Z","shell.execute_reply":"2023-07-10T13:30:03.981167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid')\nf, ax = plt.subplots(figsize = (20,18))\nax = sns.barplot( x=articles_index.price, y=articles_index.index)\nax.set_xlabel('Price by product group',fontsize=22)\nax.set_ylabel('Product group',fontsize=32)\nax.xaxis.set_tick_params(labelsize=22)\nax.yaxis.set_tick_params(labelsize=22)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:30:03.983886Z","iopub.execute_input":"2023-07-10T13:30:03.984307Z","iopub.status.idle":"2023-07-10T13:30:04.770217Z","shell.execute_reply.started":"2023-07-10T13:30:03.984264Z","shell.execute_reply":"2023-07-10T13:30:04.769065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Time cost analysis","metadata":{}},{"cell_type":"code","source":"articles_for_merge['t_dat'] = pd.to_datetime(articles_for_merge['t_dat'])","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:30:04.771736Z","iopub.execute_input":"2023-07-10T13:30:04.773080Z","iopub.status.idle":"2023-07-10T13:30:14.725759Z","shell.execute_reply.started":"2023-07-10T13:30:04.773032Z","shell.execute_reply":"2023-07-10T13:30:14.724515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_for_merge_product = articles_for_merge[articles_for_merge.product_group_name == 'Shoes']\nseries_mean = articles_for_merge_product[['t_dat','price']].groupby(pd.Grouper(key='t_dat',freq='M')).mean()\nseries_mean","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:31:37.088823Z","iopub.execute_input":"2023-07-10T13:31:37.089266Z","iopub.status.idle":"2023-07-10T13:31:42.501891Z","shell.execute_reply.started":"2023-07-10T13:31:37.089213Z","shell.execute_reply":"2023-07-10T13:31:42.500777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"series_std = articles_for_merge_product[['t_dat','price']].groupby(pd.Grouper(key='t_dat',freq='M')).std().fillna(0)\nseries_mean","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:33:17.374376Z","iopub.execute_input":"2023-07-10T13:33:17.374797Z","iopub.status.idle":"2023-07-10T13:33:17.539916Z","shell.execute_reply.started":"2023-07-10T13:33:17.374768Z","shell.execute_reply":"2023-07-10T13:33:17.538803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(1,1,figsize = (12,8))\nax.plot(series_mean, linewidth = 4)\nax.fill_between(series_mean.index,\n               (series_mean.values-2*series_std.values).ravel(),\n               (series_mean.values+2*series_std.values).ravel(),\n               alpha=0.5)\nax.set_title(f'Mean Shoes price in time')\nax.set_xlabel('month',fontsize=32)\nax.set_ylabel('shoes price',fontsize=32)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:43:22.868600Z","iopub.execute_input":"2023-07-10T13:43:22.869042Z","iopub.status.idle":"2023-07-10T13:43:23.541543Z","shell.execute_reply.started":"2023-07-10T13:43:22.869012Z","shell.execute_reply":"2023-07-10T13:43:23.540700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_for_merge_product = articles_for_merge[articles_for_merge.product_group_name == 'Bags']\nseries_mean = articles_for_merge_product[['t_dat','price']].groupby(pd.Grouper(key='t_dat',freq='M')).mean()\nseries_std = articles_for_merge_product[['t_dat','price']].groupby(pd.Grouper(key='t_dat',freq='M')).std().fillna(0)\n\nf, ax = plt.subplots(1,1,figsize = (12,8))\nax.plot(series_mean, linewidth = 4)\nax.fill_between(series_mean.index,\n               (series_mean.values-2*series_std.values).ravel(),\n               (series_mean.values+2*series_std.values).ravel(),\n               alpha=0.5)\nax.set_title(f'Mean Bags price in time')\nax.set_xlabel('month',fontsize=32)\nax.set_ylabel('Bags price',fontsize=32)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-07-10T13:46:11.498660Z","iopub.execute_input":"2023-07-10T13:46:11.499112Z","iopub.status.idle":"2023-07-10T13:46:17.267626Z","shell.execute_reply.started":"2023-07-10T13:46:11.499071Z","shell.execute_reply":"2023-07-10T13:46:17.266441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}