{"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\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        if filename.endswith('csv'):\n            print(os.path.join(dirname, filename))\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":"2023-04-18T13:56:12.540176Z","iopub.execute_input":"2023-04-18T13:56:12.540692Z","iopub.status.idle":"2023-04-18T13:57:58.673900Z","shell.execute_reply.started":"2023-04-18T13:56:12.540647Z","shell.execute_reply":"2023-04-18T13:57:58.672687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Lets continue playing with the data.","metadata":{}},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/sample_submission.csv')\narticles = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv')\ntransactions_train = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')\ncustomers = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')","metadata":{"execution":{"iopub.status.busy":"2023-04-18T13:57:58.676264Z","iopub.execute_input":"2023-04-18T13:57:58.677045Z","iopub.status.idle":"2023-04-18T13:59:29.680938Z","shell.execute_reply.started":"2023-04-18T13:57:58.676994Z","shell.execute_reply":"2023-04-18T13:59:29.679360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Im gonna start by picking 100 customers again, so I can extract the data of only these 100 customers and see if it is a managable size, since just taking the head of the transactions dataset resultet in data for only a week.","metadata":{}},{"cell_type":"code","source":"chosen_customers = customers.head(100)\nchosen_customers.head(3)","metadata":{"execution":{"iopub.status.busy":"2023-04-18T13:59:29.702435Z","iopub.execute_input":"2023-04-18T13:59:29.702932Z","iopub.status.idle":"2023-04-18T13:59:29.735738Z","shell.execute_reply.started":"2023-04-18T13:59:29.702885Z","shell.execute_reply":"2023-04-18T13:59:29.734485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"chosen_customers_id = chosen_customers['customer_id'].values.tolist()\nchosen_customers_id[0:2]","metadata":{"execution":{"iopub.status.busy":"2023-04-18T13:59:29.738349Z","iopub.execute_input":"2023-04-18T13:59:29.738990Z","iopub.status.idle":"2023-04-18T13:59:29.750720Z","shell.execute_reply.started":"2023-04-18T13:59:29.738953Z","shell.execute_reply":"2023-04-18T13:59:29.749529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I will first test by using only one customer.","metadata":{}},{"cell_type":"code","source":"test_customer1 = chosen_customers_id[0]\ntest_customer1","metadata":{"execution":{"iopub.status.busy":"2023-04-18T13:59:29.752235Z","iopub.execute_input":"2023-04-18T13:59:29.752699Z","iopub.status.idle":"2023-04-18T13:59:29.762608Z","shell.execute_reply.started":"2023-04-18T13:59:29.752662Z","shell.execute_reply":"2023-04-18T13:59:29.761446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_from_c1 = transactions_train.loc[transactions_train['customer_id'] == test_customer1]","metadata":{"execution":{"iopub.status.busy":"2023-04-18T13:59:29.764398Z","iopub.execute_input":"2023-04-18T13:59:29.764849Z","iopub.status.idle":"2023-04-18T13:59:31.978297Z","shell.execute_reply.started":"2023-04-18T13:59:29.764805Z","shell.execute_reply":"2023-04-18T13:59:31.977109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_from_c1.head(3)","metadata":{"execution":{"iopub.status.busy":"2023-04-18T13:59:31.980098Z","iopub.execute_input":"2023-04-18T13:59:31.980979Z","iopub.status.idle":"2023-04-18T13:59:31.995264Z","shell.execute_reply.started":"2023-04-18T13:59:31.980922Z","shell.execute_reply":"2023-04-18T13:59:31.993999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_from_c1.info()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T13:59:31.997092Z","iopub.execute_input":"2023-04-18T13:59:31.998030Z","iopub.status.idle":"2023-04-18T13:59:32.021495Z","shell.execute_reply.started":"2023-04-18T13:59:31.997988Z","shell.execute_reply":"2023-04-18T13:59:32.020523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now lets do this with all the 100 customers","metadata":{}},{"cell_type":"code","source":"chosen_customers.customer_id.head(2)","metadata":{"execution":{"iopub.status.busy":"2023-04-18T14:22:57.482055Z","iopub.execute_input":"2023-04-18T14:22:57.482597Z","iopub.status.idle":"2023-04-18T14:22:57.492081Z","shell.execute_reply.started":"2023-04-18T14:22:57.482549Z","shell.execute_reply":"2023-04-18T14:22:57.490954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_from_chosen_customers = transactions_train.customer_id.apply(lambda x: x in chosen_customers_id)","metadata":{"execution":{"iopub.status.busy":"2023-04-18T14:59:58.018220Z","iopub.execute_input":"2023-04-18T14:59:58.018732Z","iopub.status.idle":"2023-04-18T15:00:53.576854Z","shell.execute_reply.started":"2023-04-18T14:59:58.018688Z","shell.execute_reply":"2023-04-18T15:00:53.575089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_from_chosen_customers.head(10)","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:00:58.447730Z","iopub.execute_input":"2023-04-18T15:00:58.448250Z","iopub.status.idle":"2023-04-18T15:00:58.458009Z","shell.execute_reply.started":"2023-04-18T15:00:58.448201Z","shell.execute_reply":"2023-04-18T15:00:58.456771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Thats not really what I want, but I can just apply this to the dataset.","metadata":{}},{"cell_type":"code","source":"transactions = transactions_train[data_from_chosen_customers]","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:01:06.052344Z","iopub.execute_input":"2023-04-18T15:01:06.053149Z","iopub.status.idle":"2023-04-18T15:01:06.074640Z","shell.execute_reply.started":"2023-04-18T15:01:06.053087Z","shell.execute_reply":"2023-04-18T15:01:06.073557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.head(10)","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:01:07.385296Z","iopub.execute_input":"2023-04-18T15:01:07.386095Z","iopub.status.idle":"2023-04-18T15:01:07.400137Z","shell.execute_reply.started":"2023-04-18T15:01:07.386046Z","shell.execute_reply":"2023-04-18T15:01:07.398650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.info()","metadata":{"execution":{"iopub.status.busy":"2023-04-18T15:02:55.112481Z","iopub.execute_input":"2023-04-18T15:02:55.113059Z","iopub.status.idle":"2023-04-18T15:02:55.132717Z","shell.execute_reply.started":"2023-04-18T15:02:55.113011Z","shell.execute_reply":"2023-04-18T15:02:55.130914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}