{"nbformat": 4, "cells": [{"source": ["* based on: \n", "https://www.kaggle.com/danofer/kkbox-churn-munge-v2/\n", "\n", "* seeprated due to disk size:\n", "    * parse the (new) data, merge, parse dates, export as csv.gz (compressed).\n", "    "], "metadata": {}, "cell_type": "markdown"}, {"outputs": [], "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 in \n", "\n", "import numpy as np # linear algebra\n", "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n", "\n", "# Input data files are available in the \"../input/\" directory.\n", "# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n", "\n", "from subprocess import check_output\n", "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n", "\n", "# Any results you write to the current directory are saved as output."], "execution_count": null, "metadata": {"_uuid": "160d00d86e01a52246e98455bba62c7c68e3ab99", "collapsed": false, "_cell_guid": "0aa5efb1-95db-4ff2-861a-77e42ff5c11e"}, "cell_type": "code"}, {"outputs": [], "source": ["transactions = pd.read_csv('../input/transactions.csv')\n", "transactions = pd.concat((transactions, pd.read_csv('../input/transactions_v2.csv')), axis=0, ignore_index=True).reset_index(drop=True)\n", "\n", "\n", "transactions.membership_expire_date = pd.to_datetime(transactions.membership_expire_date,format=\"%Y%m%d\")\n", "transactions.transaction_date = pd.to_datetime(transactions.transaction_date,format=\"%Y%m%d\")\n", "\n", "print(transactions.shape)\n", "transactions.head()"], "execution_count": null, "metadata": {"collapsed": true}, "cell_type": "code"}, {"outputs": [], "source": ["transactions[\"price_paid_diff\"]  = transactions.plan_list_price -  transactions.actual_amount_paid\n", "transactions[\"transactions_expiry_transaction_days_diff\"] = ((transactions.membership_expire_date - transactions.transaction_date).dt.days) \n", "\n", "# # transactions[\"transactions_expiry_transaction_days_diff_div_plan\"] = transactions.payment_plan_days/transactions.transactions_expiry_transaction_days_diff\n"], "execution_count": null, "metadata": {"collapsed": true}, "cell_type": "code"}, {"outputs": [], "source": ["transactions.to_csv(\"kkbox_churn_transactions_v3.csv.gz\",index=False,compression=\"gzip\")"], "execution_count": null, "metadata": {"collapsed": true}, "cell_type": "code"}, {"outputs": [], "source": ["members = pd.read_csv('../input/members_v3.csv')\n", "members.registration_init_time = pd.to_datetime(transactions.registration_init_time,format=\"%Y%m%d\")\n", "members.head()"], "execution_count": null, "metadata": {"collapsed": false}, "cell_type": "code"}, {"outputs": [], "source": ["members.to_csv(\"kkbox_churn_members_v3.csv.gz\",index=False,compression=\"gzip\")"], "execution_count": null, "metadata": {"collapsed": true}, "cell_type": "code"}], "metadata": {"language_info": {"file_extension": ".py", "version": "3.6.3", "name": "python", "pygments_lexer": "ipython3", "mimetype": "text/x-python", "codemirror_mode": {"version": 3, "name": "ipython"}, "nbconvert_exporter": "python"}, "kernelspec": {"language": "python", "display_name": "Python 3", "name": "python3"}}, "nbformat_minor": 0}