{"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)\nfrom sklearn.preprocessing import OneHotEncoder, LabelEncoder\n#Visualization\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport seaborn as sns\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\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\narticles = 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')\ntrain_data = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-02T19:52:16.523276Z","iopub.execute_input":"2022-03-02T19:52:16.524804Z","iopub.status.idle":"2022-03-02T19:53:38.199781Z","shell.execute_reply.started":"2022-03-02T19:52:16.524713Z","shell.execute_reply":"2022-03-02T19:53:38.198532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Articles:')\nprint(articles.shape)\nprint(articles.keys())\nprint(articles.head())\nprint('')\nprint('Customers:')\nprint(customers.head())\nprint(customers.shape)\nprint(customers.keys())\nprint('')\nprint('Train_data:')\nprint(train_data.shape)\nprint(train_data.keys())\nprint(train_data.head())\nprint('')","metadata":{"execution":{"iopub.status.busy":"2022-03-02T19:53:38.203045Z","iopub.execute_input":"2022-03-02T19:53:38.203416Z","iopub.status.idle":"2022-03-02T19:53:38.247014Z","shell.execute_reply.started":"2022-03-02T19:53:38.203365Z","shell.execute_reply":"2022-03-02T19:53:38.24595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Articles:')\nprint(articles.isnull().sum())\nprint('')\nprint('Customers:')\nprint(customers.isnull().sum())\nprint('')\nprint('Train_data:')\nprint(train_data.isnull().sum())","metadata":{"execution":{"iopub.status.busy":"2022-03-02T19:53:38.248249Z","iopub.execute_input":"2022-03-02T19:53:38.248478Z","iopub.status.idle":"2022-03-02T19:53:46.059184Z","shell.execute_reply.started":"2022-03-02T19:53:38.248451Z","shell.execute_reply":"2022-03-02T19:53:46.057915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Data Cleaning: Handling Missing Values. What are the unique values present?\n#Customers table FN purpose unknown\nprint(customers['FN'].unique())\nprint(customers['Active'].unique())\nprint(customers['club_member_status'].unique())\nprint(customers['fashion_news_frequency'].unique())\nprint(customers['age'].unique())\n","metadata":{"execution":{"iopub.status.busy":"2022-03-02T19:53:46.061754Z","iopub.execute_input":"2022-03-02T19:53:46.062133Z","iopub.status.idle":"2022-03-02T19:53:46.427959Z","shell.execute_reply.started":"2022-03-02T19:53:46.062088Z","shell.execute_reply":"2022-03-02T19:53:46.426796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_clean = customers\n#fill FN NaN with 0\ncustomers_clean['FN'].fillna(0, inplace = True)\n\n#fill Active NaN with 0\ncustomers_clean['FN'].fillna(0, inplace = True)\n\n#leave club_member_status NaN alone\n\n#fashion_news_frequency: leave NaN alone, change NONE to None\ncustomers_clean[customers_clean['fashion_news_frequency']=='NONE'] = 'None'\n\n#drop age NaN for special analysis\ncustomers_age_compare = customers_clean.dropna(subset = ['age'])\ncustomers_age_compare = customers_age_compare[customers_age_compare['age']!='None']\nprint(customers_age_compare['age'].unique())\nprint(\"\")\nprint(customers_clean['FN'].unique())\nprint(customers_clean['Active'].unique())\nprint(customers_clean['club_member_status'].unique())\nprint(customers_clean['fashion_news_frequency'].unique())\nprint(customers_clean['age'].unique())\nprint('')\nprint(customers_clean.head())","metadata":{"execution":{"iopub.status.busy":"2022-03-02T19:53:46.429355Z","iopub.execute_input":"2022-03-02T19:53:46.42959Z","iopub.status.idle":"2022-03-02T19:53:49.102109Z","shell.execute_reply.started":"2022-03-02T19:53:46.429561Z","shell.execute_reply":"2022-03-02T19:53:49.100815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#make a column in customers showing all purchases for each category in articles\ncustomers_clean['num_purchases'] = ''\nc1 = customers_clean[customers_clean['customer_id']!='None']\nfor index,row in c1.iterrows():\n    c1.at[index,'num_purchases'] = train_data[train_data['customer_id']=='None'].count()\nprint(c1.head())\n","metadata":{"execution":{"iopub.status.busy":"2022-03-02T19:53:49.104147Z","iopub.execute_input":"2022-03-02T19:53:49.104518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(customers_clean.dtypes)","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}