{"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":"## **<span style=\"color:#A8C898;font-size:300%\"><center>Little EDA H&M</center></span>**","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-28T08:31:47.212558Z","iopub.execute_input":"2022-03-28T08:31:47.212872Z","iopub.status.idle":"2022-03-28T08:31:48.245002Z","shell.execute_reply.started":"2022-03-28T08:31:47.212835Z","shell.execute_reply":"2022-03-28T08:31:48.244049Z"}}},{"cell_type":"markdown","source":"# **<a id=\"Content\" style=\"color:#7AB495;\">Content</a>**\n* [**<span style=\"color:#7AB495;\">0. Include Data</span>**](#Data)  \n* [**<span style=\"color:#7AB495;\">1. Articles</span>**](#Articles)  \n* [**<span style=\"color:#7AB495;\">2. Customers</span>**](#Customers)  \n* [**<span style=\"color:#7AB495;\">3. Transactions</span>**](#Transactions)   ","metadata":{}},{"cell_type":"markdown","source":"<h2>Imports & settings</h2>","metadata":{}},{"cell_type":"code","source":"import numpy as np, pandas as pd, datetime as dt\nimport matplotlib.pyplot as plt; plt.style.use('ggplot')\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:00:12.832156Z","iopub.execute_input":"2022-04-05T15:00:12.832525Z","iopub.status.idle":"2022-04-05T15:00:12.841515Z","shell.execute_reply.started":"2022-04-05T15:00:12.832485Z","shell.execute_reply":"2022-04-05T15:00:12.840807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.float_format', '{:.4f}'.format)","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:00:13.553261Z","iopub.execute_input":"2022-04-05T15:00:13.554077Z","iopub.status.idle":"2022-04-05T15:00:13.557833Z","shell.execute_reply.started":"2022-04-05T15:00:13.554034Z","shell.execute_reply":"2022-04-05T15:00:13.557204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **<span id=\"Data\" style=\"color:#7AB495;\">Include Data</span>**","metadata":{}},{"cell_type":"code","source":"sub = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/sample_submission.csv')\nsub.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:00:14.708549Z","iopub.execute_input":"2022-04-05T15:00:14.709075Z","iopub.status.idle":"2022-04-05T15:00:20.087876Z","shell.execute_reply.started":"2022-04-05T15:00:14.709039Z","shell.execute_reply":"2022-04-05T15:00:20.086899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/articles.csv')\narticles.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:00:20.089953Z","iopub.execute_input":"2022-04-05T15:00:20.090297Z","iopub.status.idle":"2022-04-05T15:00:21.136593Z","shell.execute_reply.started":"2022-04-05T15:00:20.090253Z","shell.execute_reply":"2022-04-05T15:00:21.135747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/customers.csv')\ncustomers.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:00:21.137713Z","iopub.execute_input":"2022-04-05T15:00:21.137955Z","iopub.status.idle":"2022-04-05T15:00:26.957228Z","shell.execute_reply.started":"2022-04-05T15:00:21.137909Z","shell.execute_reply":"2022-04-05T15:00:26.956311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')\ndf.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:00:26.959004Z","iopub.execute_input":"2022-04-05T15:00:26.959218Z","iopub.status.idle":"2022-04-05T15:01:13.470213Z","shell.execute_reply.started":"2022-04-05T15:00:26.959192Z","shell.execute_reply":"2022-04-05T15:01:13.469595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h1>Explorary Data Analysis</h1>","metadata":{}},{"cell_type":"markdown","source":"# **<span id=\"Data\" style=\"color:#7AB495;\">Articles</span>**","metadata":{}},{"cell_type":"code","source":"articles.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:13.471182Z","iopub.execute_input":"2022-04-05T15:01:13.471853Z","iopub.status.idle":"2022-04-05T15:01:13.498717Z","shell.execute_reply.started":"2022-04-05T15:01:13.471818Z","shell.execute_reply":"2022-04-05T15:01:13.497757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize = (7,4))\nax = sns.histplot(data=articles, y='index_group_name', color='orange')\nax.set_xlabel('count')\nax.set_ylabel('index name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:13.504797Z","iopub.execute_input":"2022-04-05T15:01:13.505144Z","iopub.status.idle":"2022-04-05T15:01:13.906557Z","shell.execute_reply.started":"2022-04-05T15:01:13.505107Z","shell.execute_reply":"2022-04-05T15:01:13.905500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize = (10,7))\nax = sns.histplot(data=articles, y='garment_group_name', color='blue')\nax.set_xlabel('count')\nax.set_ylabel('product group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:13.907881Z","iopub.execute_input":"2022-04-05T15:01:13.908141Z","iopub.status.idle":"2022-04-05T15:01:14.391188Z","shell.execute_reply.started":"2022-04-05T15:01:13.908111Z","shell.execute_reply":"2022-04-05T15:01:14.390460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(10, 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":"2022-04-05T15:01:14.392604Z","iopub.execute_input":"2022-04-05T15:01:14.392880Z","iopub.status.idle":"2022-04-05T15:01:15.361674Z","shell.execute_reply.started":"2022-04-05T15:01:14.392849Z","shell.execute_reply":"2022-04-05T15:01:15.360660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h3>Groups Ladieswear and Children/Baby have subgroups.</h3>","metadata":{}},{"cell_type":"code","source":"articles['index_group_name'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:15.363185Z","iopub.execute_input":"2022-04-05T15:01:15.363502Z","iopub.status.idle":"2022-04-05T15:01:15.379537Z","shell.execute_reply.started":"2022-04-05T15:01:15.363459Z","shell.execute_reply":"2022-04-05T15:01:15.378689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles['index_name'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:15.383561Z","iopub.execute_input":"2022-04-05T15:01:15.384267Z","iopub.status.idle":"2022-04-05T15:01:15.399801Z","shell.execute_reply.started":"2022-04-05T15:01:15.384229Z","shell.execute_reply":"2022-04-05T15:01:15.399194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(10, 7))\nax = sns.histplot(data=articles, y='index_group_name', hue='index_name', multiple=\"stack\")\nax.set_xlabel('count by garment group')\nax.set_ylabel('garment group')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:15.401457Z","iopub.execute_input":"2022-04-05T15:01:15.401942Z","iopub.status.idle":"2022-04-05T15:01:16.262504Z","shell.execute_reply.started":"2022-04-05T15:01:15.401894Z","shell.execute_reply":"2022-04-05T15:01:16.261587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for column in articles.columns:\n    print('{:30}:{:5.2%}'.format(column, articles[column].isna().sum()/articles.shape[0]))","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:16.263727Z","iopub.execute_input":"2022-04-05T15:01:16.263990Z","iopub.status.idle":"2022-04-05T15:01:16.453684Z","shell.execute_reply.started":"2022-04-05T15:01:16.263959Z","shell.execute_reply":"2022-04-05T15:01:16.452831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Almost no missing values","metadata":{}},{"cell_type":"markdown","source":"# **<span id=\"Customers\" style=\"color:#7AB495;\">Customers</span>**","metadata":{"execution":{"iopub.status.busy":"2022-04-01T14:33:16.279594Z","iopub.execute_input":"2022-04-01T14:33:16.28022Z","iopub.status.idle":"2022-04-01T14:33:16.285867Z","shell.execute_reply.started":"2022-04-01T14:33:16.280168Z","shell.execute_reply":"2022-04-01T14:33:16.284745Z"}}},{"cell_type":"code","source":"customers.columns","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:16.455076Z","iopub.execute_input":"2022-04-05T15:01:16.455297Z","iopub.status.idle":"2022-04-05T15:01:16.461556Z","shell.execute_reply.started":"2022-04-05T15:01:16.455270Z","shell.execute_reply":"2022-04-05T15:01:16.460640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**FN - 1 if a customer get Fashion News newsletter**\n\n**Active - 1 if the customer is active for communication**","metadata":{}},{"cell_type":"code","source":"customers['FN'].unique(), customers['Active'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:16.462862Z","iopub.execute_input":"2022-04-05T15:01:16.463148Z","iopub.status.idle":"2022-04-05T15:01:16.509527Z","shell.execute_reply.started":"2022-04-05T15:01:16.463107Z","shell.execute_reply":"2022-04-05T15:01:16.508650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Club membership status**","metadata":{}},{"cell_type":"code","source":"customers['club_member_status'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:16.510616Z","iopub.execute_input":"2022-04-05T15:01:16.510829Z","iopub.status.idle":"2022-04-05T15:01:16.662899Z","shell.execute_reply.started":"2022-04-05T15:01:16.510803Z","shell.execute_reply":"2022-04-05T15:01:16.662128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers[customers['club_member_status'].isna()]","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:16.664216Z","iopub.execute_input":"2022-04-05T15:01:16.664463Z","iopub.status.idle":"2022-04-05T15:01:16.842195Z","shell.execute_reply.started":"2022-04-05T15:01:16.664433Z","shell.execute_reply":"2022-04-05T15:01:16.841167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"nan -> 'None'","metadata":{}},{"cell_type":"code","source":"customers.loc[customers['club_member_status'] == np.nan, 'club_member_status'] = 'None'","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:16.843528Z","iopub.execute_input":"2022-04-05T15:01:16.843757Z","iopub.status.idle":"2022-04-05T15:01:16.871457Z","shell.execute_reply.started":"2022-04-05T15:01:16.843730Z","shell.execute_reply":"2022-04-05T15:01:16.870584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**News frequency**","metadata":{}},{"cell_type":"code","source":"customers['fashion_news_frequency'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:16.872786Z","iopub.execute_input":"2022-04-05T15:01:16.873259Z","iopub.status.idle":"2022-04-05T15:01:17.031798Z","shell.execute_reply.started":"2022-04-05T15:01:16.873220Z","shell.execute_reply":"2022-04-05T15:01:17.030633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**NONE, None and nan. 3 values 1 meaning - fix it**","metadata":{}},{"cell_type":"code","source":"customers.loc[customers['fashion_news_frequency'].isin(['NONE', 'None', np.nan]), 'fashion_news_frequency'] = 'None'\ncustomers['fashion_news_frequency'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:17.033774Z","iopub.execute_input":"2022-04-05T15:01:17.034144Z","iopub.status.idle":"2022-04-05T15:01:17.297692Z","shell.execute_reply.started":"2022-04-05T15:01:17.034110Z","shell.execute_reply":"2022-04-05T15:01:17.296808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Age**","metadata":{}},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nf, ax = plt.subplots(figsize=(10,7))\nax = sns.histplot(data=customers, x='age', bins=50, color='green')\nax.set_xlabel('Distribution of the age')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:17.299017Z","iopub.execute_input":"2022-04-05T15:01:17.299275Z","iopub.status.idle":"2022-04-05T15:01:17.822129Z","shell.execute_reply.started":"2022-04-05T15:01:17.299244Z","shell.execute_reply":"2022-04-05T15:01:17.821096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers['fashion_news_frequency'].index","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:17.823561Z","iopub.execute_input":"2022-04-05T15:01:17.823785Z","iopub.status.idle":"2022-04-05T15:01:17.829671Z","shell.execute_reply.started":"2022-04-05T15:01:17.823757Z","shell.execute_reply":"2022-04-05T15:01:17.828826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Distribution of news frequency**","metadata":{}},{"cell_type":"code","source":"pie_data = customers.groupby('fashion_news_frequency')['customer_id'].count()\npie_data","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:17.831045Z","iopub.execute_input":"2022-04-05T15:01:17.831310Z","iopub.status.idle":"2022-04-05T15:01:18.133735Z","shell.execute_reply.started":"2022-04-05T15:01:17.831281Z","shell.execute_reply":"2022-04-05T15:01:18.132999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(10,7))\ncolors = sns.color_palette('deep')\nax.pie(pie_data, labels=pie_data.index, colors = colors)\nax.set_facecolor('lightgrey')\nax.set_xlabel('Distribution of news frequency')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:18.134847Z","iopub.execute_input":"2022-04-05T15:01:18.136211Z","iopub.status.idle":"2022-04-05T15:01:18.260239Z","shell.execute_reply.started":"2022-04-05T15:01:18.136179Z","shell.execute_reply":"2022-04-05T15:01:18.259524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **<span id=\"Transactions\" style=\"color:#7AB495;\">Transactions</span>**","metadata":{}},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:18.261487Z","iopub.execute_input":"2022-04-05T15:01:18.261733Z","iopub.status.idle":"2022-04-05T15:01:18.269950Z","shell.execute_reply.started":"2022-04-05T15:01:18.261701Z","shell.execute_reply":"2022-04-05T15:01:18.268896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Price","metadata":{}},{"cell_type":"code","source":"f, ax = plt.subplots(figsize = (10, 7))\nplt.xlim(0, 0.3)\nax = sns.histplot(data = df, x = 'price', bins = 75, color = 'green')\nax.set_xlabel('Distribution of price')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:18.271390Z","iopub.execute_input":"2022-04-05T15:01:18.271902Z","iopub.status.idle":"2022-04-05T15:01:26.712099Z","shell.execute_reply.started":"2022-04-05T15:01:18.271858Z","shell.execute_reply":"2022-04-05T15:01:26.711312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['price'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:26.713258Z","iopub.execute_input":"2022-04-05T15:01:26.713471Z","iopub.status.idle":"2022-04-05T15:01:27.865221Z","shell.execute_reply.started":"2022-04-05T15:01:26.713445Z","shell.execute_reply":"2022-04-05T15:01:27.864345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize = (12,8))\nax = sns.boxplot(data = df, x = 'price', color = \"green\")\nax.set_xlabel('Price boxplot')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:27.866511Z","iopub.execute_input":"2022-04-05T15:01:27.866740Z","iopub.status.idle":"2022-04-05T15:01:32.482875Z","shell.execute_reply.started":"2022-04-05T15:01:27.866711Z","shell.execute_reply":"2022-04-05T15:01:32.481970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Sales_channel_id","metadata":{}},{"cell_type":"code","source":"pie_data = df.groupby('sales_channel_id').count()['customer_id']\npie_data","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:32.486295Z","iopub.execute_input":"2022-04-05T15:01:32.486529Z","iopub.status.idle":"2022-04-05T15:01:41.064800Z","shell.execute_reply.started":"2022-04-05T15:01:32.486502Z","shell.execute_reply":"2022-04-05T15:01:41.063970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize = (10, 7))\ncolors = sns.color_palette('deep')\nax.pie(pie_data, labels=['Online', 'Offline'], colors = colors)\nax.set_facecolor('lightgrey')\nax.set_xlabel('Distribution of sales channel')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:01:41.066205Z","iopub.execute_input":"2022-04-05T15:01:41.066435Z","iopub.status.idle":"2022-04-05T15:01:41.190750Z","shell.execute_reply.started":"2022-04-05T15:01:41.066408Z","shell.execute_reply":"2022-04-05T15:01:41.184579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **<span style=\"color:#85CDD0;font-size:100%\"><center>Thanks for reading! If you find this notebook interesting, please, support with an upvote :)</center></span>**","metadata":{"execution":{"iopub.status.busy":"2022-04-05T14:32:02.00104Z","iopub.execute_input":"2022-04-05T14:32:02.001322Z","iopub.status.idle":"2022-04-05T14:32:02.008395Z","shell.execute_reply.started":"2022-04-05T14:32:02.001292Z","shell.execute_reply":"2022-04-05T14:32:02.006828Z"}}},{"cell_type":"markdown","source":"# **<span style=\"color:#85CDD0;font-size:100%\"><center>If you find error or know how to improve this notebook, write the comment! Thanks!)</center></span>**","metadata":{}}]}