{"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\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport pylab as pl\nimport numpy as np\n%matplotlib inline\nimport seaborn as sns # nice visualisations\nimport datetime as dt # library to opearate on dates\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-21T10:33:29.522554Z","iopub.execute_input":"2022-03-21T10:33:29.522851Z","iopub.status.idle":"2022-03-21T10:33:30.696834Z","shell.execute_reply.started":"2022-03-21T10:33:29.522823Z","shell.execute_reply":"2022-03-21T10:33:30.696012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA GOAL  \nThe goal of this file is to discover:\n\n1. Clean and prepare the custumers dataset \n2. Discover the age distribution of custumers.\n3. Discover how custumers age distribution may be related with the other variables  ","metadata":{}},{"cell_type":"markdown","source":"## Helper function that allows to print the distribuction of custumers age with respect to some other variable","metadata":{}},{"cell_type":"code","source":"def ageDistributionPlot(df, legend):\n    fig, ax = plt.subplots(figsize=(10,5))\n    ax = sns.histplot(data=df, x='age', bins=df['age'].nunique(), color='orange', stat=\"percent\")\n    ax.set_xlabel(legend)\n    for loc in ['bottom', 'left']:\n        ax.spines[loc].set_visible(True)\n        ax.spines[loc].set_linewidth(2)\n        ax.spines[loc].set_color('black')\n    ax.text(12, 5.5, legend , color='black', fontsize=10, ha='left', va='bottom', weight='bold', style='italic')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:33:30.698124Z","iopub.execute_input":"2022-03-21T10:33:30.698483Z","iopub.status.idle":"2022-03-21T10:33:30.707284Z","shell.execute_reply.started":"2022-03-21T10:33:30.698430Z","shell.execute_reply":"2022-03-21T10:33:30.706294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Reading the Dataset and checking the column structure and unique values","metadata":{}},{"cell_type":"code","source":"customers_df = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')\ncustomers_df.head(1)","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:33:30.938328Z","iopub.execute_input":"2022-03-21T10:33:30.939002Z","iopub.status.idle":"2022-03-21T10:33:36.686077Z","shell.execute_reply.started":"2022-03-21T10:33:30.938952Z","shell.execute_reply":"2022-03-21T10:33:36.684951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colunas = pd.DataFrame(columns={'Column Name', 'Unique Values'})\nfor col in customers_df:\n    new_df = pd.DataFrame({'Column Name':[col], 'Unique Values': [customers_df[col].unique().size]})\n    colunas = colunas.append( new_df)\n    #print(col + \" - \" + str(artigos[col].unique().size))\ncolunas = colunas[['Column Name', 'Unique Values']]\ncolunas.head(7)","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:33:36.688062Z","iopub.execute_input":"2022-03-21T10:33:36.688286Z","iopub.status.idle":"2022-03-21T10:33:38.193271Z","shell.execute_reply.started":"2022-03-21T10:33:36.688260Z","shell.execute_reply":"2022-03-21T10:33:38.192347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Removing duplicates","metadata":{}},{"cell_type":"code","source":"active = customers_df['Active'].drop_duplicates()\nprint(active)","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:33:38.194338Z","iopub.execute_input":"2022-03-21T10:33:38.194569Z","iopub.status.idle":"2022-03-21T10:33:38.225561Z","shell.execute_reply.started":"2022-03-21T10:33:38.194540Z","shell.execute_reply":"2022-03-21T10:33:38.223831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_df = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')\ncustomers_df.head(1)","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:33:38.227258Z","iopub.execute_input":"2022-03-21T10:33:38.227633Z","iopub.status.idle":"2022-03-21T10:33:41.932621Z","shell.execute_reply.started":"2022-03-21T10:33:38.227560Z","shell.execute_reply":"2022-03-21T10:33:41.931720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Age distribution - All customers","metadata":{}},{"cell_type":"code","source":"ageDistributionPlot(customers_df,'Custumer\\'s Age Distribution ')","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:35:02.680614Z","iopub.execute_input":"2022-03-21T10:35:02.681502Z","iopub.status.idle":"2022-03-21T10:35:03.232063Z","shell.execute_reply.started":"2022-03-21T10:35:02.681436Z","shell.execute_reply":"2022-03-21T10:35:03.230787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Filling empty values with 0 (For FN anda Active)","metadata":{}},{"cell_type":"code","source":"customers_df[['FN','Active']] = customers_df[['FN','Active']].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:43:43.405305Z","iopub.execute_input":"2022-03-21T10:43:43.405898Z","iopub.status.idle":"2022-03-21T10:43:43.437934Z","shell.execute_reply.started":"2022-03-21T10:43:43.405853Z","shell.execute_reply":"2022-03-21T10:43:43.437216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Custumers Age Distribution vs FN","metadata":{}},{"cell_type":"code","source":"fn_age_0 = customers_df[customers_df['FN']==0]\nageDistributionPlot(fn_age_0,'FN == 0 Age Distribution ')","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:44:12.797845Z","iopub.execute_input":"2022-03-21T10:44:12.798143Z","iopub.status.idle":"2022-03-21T10:44:13.393392Z","shell.execute_reply.started":"2022-03-21T10:44:12.798103Z","shell.execute_reply":"2022-03-21T10:44:13.392375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fn_age_1 = customers_df[customers_df['FN']==1]\nageDistributionPlot(fn_age_1,'FN == 1 Age Distribution ')","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:44:43.804021Z","iopub.execute_input":"2022-03-21T10:44:43.804628Z","iopub.status.idle":"2022-03-21T10:44:44.305518Z","shell.execute_reply.started":"2022-03-21T10:44:43.804591Z","shell.execute_reply":"2022-03-21T10:44:44.304652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Custumers Age Distribution vs Active","metadata":{}},{"cell_type":"code","source":"active_age_0 = customers_df[customers_df['Active']==0]\nageDistributionPlot(active_age_0,'Active == 0 Age Distribution ')","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:45:09.701829Z","iopub.execute_input":"2022-03-21T10:45:09.702118Z","iopub.status.idle":"2022-03-21T10:45:10.273310Z","shell.execute_reply.started":"2022-03-21T10:45:09.702088Z","shell.execute_reply":"2022-03-21T10:45:10.272383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"active_age_1 = customers_df[customers_df['Active']==1]\nageDistributionPlot(active_age_1,'Active == 1 Age Distribution ')","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:45:15.292113Z","iopub.execute_input":"2022-03-21T10:45:15.292607Z","iopub.status.idle":"2022-03-21T10:45:15.776730Z","shell.execute_reply.started":"2022-03-21T10:45:15.292572Z","shell.execute_reply":"2022-03-21T10:45:15.776063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Custumers Age Distribution vs Club Member Status","metadata":{}},{"cell_type":"code","source":"cms = customers_df['club_member_status'].drop_duplicates()\ncms.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:45:41.316774Z","iopub.execute_input":"2022-03-21T10:45:41.317220Z","iopub.status.idle":"2022-03-21T10:45:41.412516Z","shell.execute_reply.started":"2022-03-21T10:45:41.317186Z","shell.execute_reply":"2022-03-21T10:45:41.411553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cms_active =customers_df[customers_df['club_member_status']=='ACTIVE']\nageDistributionPlot(cms_active,'club_member_status = ACTIVE Age Distribution ')","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:45:43.125448Z","iopub.execute_input":"2022-03-21T10:45:43.125729Z","iopub.status.idle":"2022-03-21T10:45:44.032854Z","shell.execute_reply.started":"2022-03-21T10:45:43.125700Z","shell.execute_reply":"2022-03-21T10:45:44.031839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cms_lc =customers_df[customers_df['club_member_status']=='LEFT CLUB']\nageDistributionPlot(cms_lc,'club_member_status = LEFT CLUB Age Distribution ')","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:46:04.045900Z","iopub.execute_input":"2022-03-21T10:46:04.046191Z","iopub.status.idle":"2022-03-21T10:46:04.562915Z","shell.execute_reply.started":"2022-03-21T10:46:04.046158Z","shell.execute_reply":"2022-03-21T10:46:04.561805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cms_lc.count()","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:46:04.695595Z","iopub.execute_input":"2022-03-21T10:46:04.695885Z","iopub.status.idle":"2022-03-21T10:46:04.706162Z","shell.execute_reply.started":"2022-03-21T10:46:04.695855Z","shell.execute_reply":"2022-03-21T10:46:04.705215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cms_pc =customers_df[customers_df['club_member_status']=='PRE-CREATE']\nageDistributionPlot(cms_pc,'club_member_status = PRE-CREATE Age Distribution ')","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:46:12.158587Z","iopub.execute_input":"2022-03-21T10:46:12.158868Z","iopub.status.idle":"2022-03-21T10:46:12.908228Z","shell.execute_reply.started":"2022-03-21T10:46:12.158841Z","shell.execute_reply":"2022-03-21T10:46:12.907244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cms_pc.count()","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:46:22.436340Z","iopub.execute_input":"2022-03-21T10:46:22.436640Z","iopub.status.idle":"2022-03-21T10:46:22.496672Z","shell.execute_reply.started":"2022-03-21T10:46:22.436610Z","shell.execute_reply":"2022-03-21T10:46:22.495683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fnews = customers_df['fashion_news_frequency'].drop_duplicates()\nprint(fnews)","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:46:28.665939Z","iopub.execute_input":"2022-03-21T10:46:28.666265Z","iopub.status.idle":"2022-03-21T10:46:28.761531Z","shell.execute_reply.started":"2022-03-21T10:46:28.666233Z","shell.execute_reply":"2022-03-21T10:46:28.760505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fn_none =customers_df[customers_df['fashion_news_frequency']=='NONE']\nageDistributionPlot(fn_none,'fashion_news_frequency = None Age Distribution ')\nfn_reg =customers_df[customers_df['fashion_news_frequency']=='Regularly']\nageDistributionPlot(fn_reg,'fashion_news_frequency = Regularly Age Distribution ')\nfn_nan =customers_df[customers_df['fashion_news_frequency']=='NaN']\nageDistributionPlot(fn_nan,'fashion_news_frequency = NaN Age Distribution ')\nfn_m =customers_df[customers_df['fashion_news_frequency']=='Monthly']\nageDistributionPlot(fn_m,'fashion_news_frequency = Monthly Age Distribution ')\nfn_none2 =customers_df[customers_df['fashion_news_frequency']=='None']\nageDistributionPlot(fn_none2,'fashion_news_frequency = None2  Age Distribution ')\n","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:46:37.631328Z","iopub.execute_input":"2022-03-21T10:46:37.631623Z","iopub.status.idle":"2022-03-21T10:46:40.989870Z","shell.execute_reply.started":"2022-03-21T10:46:37.631595Z","shell.execute_reply":"2022-03-21T10:46:40.988894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(fn_none.count())\nprint(fn_reg.count())\nprint(fn_nan.count())\nprint(fn_m.count())\nprint(fn_none2.count())","metadata":{"execution":{"iopub.status.busy":"2022-03-21T10:46:45.139052Z","iopub.execute_input":"2022-03-21T10:46:45.139359Z","iopub.status.idle":"2022-03-21T10:46:45.789215Z","shell.execute_reply.started":"2022-03-21T10:46:45.139325Z","shell.execute_reply":"2022-03-21T10:46:45.788488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}