{"nbformat_minor": 1, "metadata": {"language_info": {"nbconvert_exporter": "python", "file_extension": ".py", "mimetype": "text/x-python", "codemirror_mode": {"version": 3, "name": "ipython"}, "version": "3.6.3", "name": "python", "pygments_lexer": "ipython3"}, "kernelspec": {"language": "python", "name": "python3", "display_name": "Python 3"}}, "cells": [{"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."], "cell_type": "code", "metadata": {"_uuid": "07a220e4ffd9ac56fd1413e6cb194ddf9e2693ca", "_cell_guid": "c9897e82-0c86-4d4e-aee9-14e90833112e"}, "execution_count": null, "outputs": []}, {"source": ["members = pd.read_csv('../input/members_v2.csv')"], "cell_type": "code", "metadata": {"_uuid": "d8bc27f9927f962201c6f3a4baac1212ef001ded", "_cell_guid": "fa104583-372b-40ae-b311-8399109ae85d"}, "execution_count": null, "outputs": []}, {"source": [], "cell_type": "code", "metadata": {"_uuid": "492fe4dbaeb987fd34b1a2e1289f028888e5fb33", "_cell_guid": "b62d6f56-4c19-410b-a975-03492b67aa37", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["train = pd.read_csv('../input/train.csv')"], "cell_type": "code", "metadata": {"_uuid": "b2621dfdd534393e53ab9a1ff4a78d17da177b92", "_cell_guid": "2bed5572-f450-4618-8a44-0250d336cba2", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["transactions = pd.read_csv('../input/transactions.csv')"], "cell_type": "code", "metadata": {"_uuid": "726fdbac4a8c17f9ce560ecdbf2700b3dc486c6c", "_cell_guid": "08ea9372-4b7c-4a5a-8a9a-ef5e5293474e", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["#user_logs = pd.read_csv('../input/user_logs.csv')"], "cell_type": "code", "metadata": {"_uuid": "a30a5095dabd51d508552791ab6bb24bfd7a4d1d", "_cell_guid": "a5cb394b-c354-4b41-99db-fbb775e75f46", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["members.head()"], "cell_type": "code", "metadata": {"_uuid": "51bc808548084c66694524c276184b52edbf9382", "_cell_guid": "af4b28eb-40be-4961-9796-8e6ae1f7eea9"}, "execution_count": null, "outputs": []}, {"source": ["members.groupby('msno')"], "cell_type": "code", "metadata": {"_uuid": "d9f306cedb2dbf19e774d1dff22c41135e19b652", "_cell_guid": "61e62e04-1943-4c6f-b3f8-dbcf8603d82d"}, "execution_count": null, "outputs": []}, {"source": ["transactions.head() #use parse dates in next import"], "cell_type": "code", "metadata": {"_uuid": "75372abde81fdf7561998bf02dadb1033886fc01", "_cell_guid": "cde001a3-cbc0-4b56-bda9-f39def4536f3"}, "execution_count": null, "outputs": []}, {"source": ["train.head()"], "cell_type": "code", "metadata": {"_uuid": "9137f993793c433f0694394df23d4202382a2677", "_cell_guid": "a61a8ec7-6f29-46fb-8f56-cb410793e55d"}, "execution_count": null, "outputs": []}, {"source": ["train.shape"], "cell_type": "code", "metadata": {"_uuid": "94add97dc01ddf8cd15a8b6bb70aea6ed5a3478c", "_cell_guid": "4a71f8f5-867d-41a1-8f04-30654d71adb9", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["transactions.shape"], "cell_type": "code", "metadata": {"_uuid": "db5bd516665b348403d59d02b53e5fdffb921d39", "_cell_guid": "75b6f0d0-6645-4386-99ea-080b0489dfea", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["members.shape"], "cell_type": "code", "metadata": {"_uuid": "f72340dd5b5210bf531eace6dbe43e883f230e07", "_cell_guid": "488ae2fc-4255-45b0-9a3d-5851af87917f", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df = pd.merge(train, transactions, how = 'inner', on = 'msno')"], "cell_type": "code", "metadata": {"_uuid": "79ce558f2d58b2822be132b7753f79b71b1ff5b7", "_cell_guid": "03360803-ad3c-417c-adb0-7a0e453b7c73", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df.shape"], "cell_type": "code", "metadata": {"_uuid": "363594b87183fc665a36745e4ca1664c7be05739", "_cell_guid": "28f9d776-ff8c-40e2-9865-32d1548a503e", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df = pd.merge(df, members, how = 'left', on = 'msno')"], "cell_type": "code", "metadata": {"_uuid": "fb53ea24f58bdd78c5102a9827b3aa86aa6db7a7", "_cell_guid": "0e8d4b1f-9333-44b1-9eea-9c275d33e70e", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df.shape"], "cell_type": "code", "metadata": {"_uuid": "f384f5324041d61e73cc442cb5b15b99f046dce0", "_cell_guid": "60ddeebd-3e10-4b03-8ce6-49e33d67fa14", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df.head()"], "cell_type": "code", "metadata": {"_uuid": "6384d57aa17554265ae70f98ff7a86321b5710d0", "_cell_guid": "c5fb56fb-913b-4114-811f-2b6cb2501cbe", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df.msno.nunique()"], "cell_type": "code", "metadata": {"_uuid": "f989c45130d93bcbb2be3dc319831938b2f83664", "_cell_guid": "440b34c9-84e1-4a77-a5a4-d3ba0fddd976", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df.dtypes"], "cell_type": "code", "metadata": {"_uuid": "c91ea368aa5c498224b5abc6007e356662c7aff6", "_cell_guid": "c5d80125-d90a-4950-95ef-11644661893f", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df[['payment_plan_days', 'plan_list_price']].agg(['min', 'average', 'max'])"], "cell_type": "code", "metadata": {"_uuid": "21ac2e130960d26ebd524759f226d5839b6cc5c5", "_cell_guid": "74df0297-4686-4acf-a6c4-550797672de8", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df['membership_expire_date'] = pd.to_datetime(df['membership_expire_date'], format='%Y%m%d')"], "cell_type": "code", "metadata": {"_uuid": "de810eedf839482a0da7d015718a2784b8a9b372", "_cell_guid": "e5ff252a-5bae-4680-b6c2-329f4a7be516", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df.head()\n", "\n", "#df = df.drop('membership_expire_date_clean', axis=1)"], "cell_type": "code", "metadata": {"_uuid": "68670fdffe8d298d9af577cd45d2a94f41eed094", "_cell_guid": "052de81e-c30f-46ba-aab5-06857a58b090", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": [], "cell_type": "code", "metadata": {"_uuid": "0beeaa557d3ed82308237ca3d97e8eeeb1ce65d1", "_cell_guid": "35cbde3b-faff-44ac-9766-b6cf16bbf320", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df['transaction_date'] = pd.to_datetime(df['transaction_date'], format='%Y%m%d')"], "cell_type": "code", "metadata": {"_uuid": "ea7aa7e36985e0342bd54e378eee2f5b8a3ef682", "_cell_guid": "99a5298e-d882-4c02-83a3-23f0b3015a75", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df['registration_init_time'] = pd.to_datetime(df['registration_init_time'], format='%Y%m%d')"], "cell_type": "code", "metadata": {"_uuid": "04116164b9c93ebd55758a85b1f36fc2d3255d45", "_cell_guid": "0ee192d6-e32b-4829-be16-7e6e22124554", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df.head()"], "cell_type": "code", "metadata": {"_uuid": "f6dafd558862a59c76a2a416cb45fb40a3426253", "_cell_guid": "fe969219-3588-4f69-85af-bc4c8aca52b7", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df[['transaction_date', 'membership_expire_date', 'registration_init_time']].describe()"], "cell_type": "code", "metadata": {"_uuid": "35aeb53119369025cf291722a47a34ba9040df9a", "_cell_guid": "1c360a9a-f922-43e0-8eb7-b65733f570f8", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df[df.membership_expire_date == '2023-08-17']"], "cell_type": "code", "metadata": {"_uuid": "fefb5868ee687e6d8b7c856238a8d1400546e593", "_cell_guid": "e25f0ec6-9d25-4988-94c2-9b35bcfb9dc4", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df[df.msno == 'f/CqixCvjsoTwQRY8A09SMBMsM0cRcG8BSUe48Bd2Mg='].sort_values('membership_expire_date')"], "cell_type": "code", "metadata": {"_uuid": "47ca9e8a09fb89403e6ba18067e21f231bc77284", "_cell_guid": "5c677c55-1088-4da8-963f-79a688c71a92"}, "execution_count": null, "outputs": []}, {"source": ["df.groupby('payment_method_id').count()"], "cell_type": "code", "metadata": {"_uuid": "39b781cc5a54d545f454a83ec1936083e542a8c6", "_cell_guid": "bc69aff8-34f5-4452-9caf-b6095cbc005f", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df[df.payment_plan_days == 30].groupby('plan_list_price').count()"], "cell_type": "code", "metadata": {"_uuid": "7e8a3ce9fb02c419426eb216d4579fb4f20360e8", "_cell_guid": "2183d916-9a3d-42f9-b11d-183bb93b69f1", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": [], "cell_type": "code", "metadata": {"_uuid": "48f1af71f5b64ed68cc29da2b9432f4c29ef86ce", "_cell_guid": "0f6eea89-a008-450a-be04-4bd98c3e5929", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import numpy as np\n", "import scipy.stats as stats\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt\n", "sns.set_style('whitegrid')\n", "\n", "%config InlineBackend.figure_format = 'retina'\n", "%matplotlib inline\n"], "cell_type": "code", "metadata": {"_uuid": "85095c55d124c77ad8b1a208894b2bcb9682c4e2", "_cell_guid": "3f51b87a-2f7e-4a44-a1d7-c3c190c94148", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["#import datetime as dt\n", "\n", "#df['membership_expire_date_tuple'] = dt.timetuple(df.membership_expire_date)"], "cell_type": "code", "metadata": {"_uuid": "cab94455892bbc6e593cc80079e6b7035bf5005f", "_cell_guid": "7cf3ab7b-6195-4659-8d90-f9d7c5ce9373", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["import matplotlib.pyplot as plt\n", "\n", "\n", "ax = plt.gca()\n", "ax.hist(df['membership_expire_date'].values, bins= 30)"], "cell_type": "code", "metadata": {"_uuid": "b1a3e920be875a5555ba38fe1ae3b329f14c47bf", "_cell_guid": "45589a57-3d97-41e4-9262-2aaa247c3819", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df['membership_expire_date'].groupby([df['membership_expire_date'].dt.year, df['membership_expire_date'].dt.month]).count()"], "cell_type": "code", "metadata": {"_uuid": "ba710c543b0823fa76d76148302c0daa6d377cc7", "_cell_guid": "d872a4ad-f5e6-411a-ba06-bebda6056475", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": ["df.groupby(df.msno).max().reset_index()"], "cell_type": "code", "metadata": {"_uuid": "3bf6a0e99657f16e91bcf3f2e07f1f87edec0986", "_cell_guid": "e62cfa27-b7af-4a51-855a-9212c342d1f8", "collapsed": true}, "execution_count": null, "outputs": []}, {"source": [], "cell_type": "code", "metadata": {"_uuid": "fefb3ef5df0d8f44004caa9f3bbcf0a60f3a84ec", "_cell_guid": "d5547654-1a7e-4308-9614-c2476aa9f007", "collapsed": true}, "execution_count": null, "outputs": []}], "nbformat": 4}