{"nbformat_minor": 1, "cells": [{"source": ["# Get further transactions information, \n", "# range 1: 30 , from transaction.csv\n", "# check if this variables are informative \n", "# cross_val_score /feature importance check \n", "from subprocess import check_output\n", "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n", "\n", "import numpy as np \n", "import pandas as pd \n", "import gc; gc.enable() \n", "\n", "train = pd.read_csv(\"../input/train.csv\")\n", "test = pd.read_csv(\"../input/sample_submission_zero.csv\")\n", "transactions  = pd.read_csv(\"../input/transactions.csv\")\n", "\n", "\n", "train_iter = transactions.sort_values(by = ['transaction_date'], ascending = [False])\n", "\n", "for i in range(1, 30, 1):\n", "\n", "    \n", "    train_sub = train_iter.drop_duplicates(subset= 'msno', keep = 'first')\n", "    ind = train_sub.index\n", "    \n", "    train_iter =  train_iter.drop(ind, axis = 0)\n", "\n", "    print(\"Wymiar train_iter  po\", i, \"iters\", train_iter.shape[0])\n", "    print(\"Wymiar train_sub   po \", i, \"iters\", train_sub.shape[0])\n", "\n", "    \n", "# Does not work in my local python dist\n", "#    train_sub.rename(columns = {\n", "#        \"payment_method_id\": \"payment_method_id\" + str(i) , \n", "#        \"payment_plan_days\": \"payment_plan_days\" + str(i) , \n", "##        \"plan_list_price\"  : \"plan_list_price\"   + str(i),\n", " #       \"actual_amount_paid\" : \"actual_amount_paid\" + str(i),\n", " #       \"is_auto_renew\"     : \"is_auto_renew\" + str(i),\n", " #       \"transaction_date\"  : \"transaction_date\"  + str(i),\n", " #       \"membership_expire_date\"  : \"membership_expire_date\"  + str(i),\n", " #       \"is_cancel\"  : \"is_cancel\"  + str(i)\n", " #   })   \n", "  \n", "    \n", "    train_sub.columns = ['msno', 'payment_method_id' + str(i), \n", "                    'payment_plan_days' + str(i), \n", "                    'plan_list_price' + str(i), \n", "                    'actual_amount_paid' + str(i), \n", "                    'is_auto_renew' + str(i), \n", "                    'transaction_date' + str(i), \n", "                    'membership_expire_date' + str(i), \n", "                    'is_cancel' + str(i)]\n", "    \n", "    \n", "    train = pd.merge(train, train_sub, on = 'msno', how = 'left')\n", "    test  = pd.merge(test, train_sub, on = 'msno', how = 'left')\n", "    gc.collect()\n", "\n", "print(\"train  rows\", train.shape[0], \"train cols\", train.shape[1])\n", "print(\"test rows\", test.shape[0], \"test cols\", test.shape[1])\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "# Any results you write to the current directory are saved as output."], "execution_count": null, "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "ab1421e0-0706-4b38-b9e7-4d6dc8009607", "_uuid": "14d83d0e4b831d32ecc0a834ee1e0a9bc5bdbdf2"}}], "nbformat": 4, "metadata": {"language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "3.6.3", "codemirror_mode": {"name": "ipython", "version": 3}, "name": "python", "pygments_lexer": "ipython3", "file_extension": ".py"}, "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}}}