{"nbformat": 4, "nbformat_minor": 1, "cells": [{"execution_count": null, "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", "import matplotlib.pyplot as plt # for data visualisation\n", "import seaborn as sns\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"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "78b646f3-5c24-489e-8633-1e240ec47b8b", "_uuid": "91e61c480dee886a93f107875ee6a2b6490be767"}}, {"execution_count": null, "source": ["# Importing the holidays event data file\n", "holidays_events = pd.read_csv('../input/holidays_events.csv')\n", "holidays_events.describe()"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "2f715059-cdfe-4d27-a856-e645d38fbf37", "_uuid": "d8c1b7f38d6fd236c2ad38fc6f69323c3e87bec5"}}, {"execution_count": null, "source": ["# Importing the items data file\n", "items = pd.read_csv('../input/items.csv')\n", "items.describe(include = 'all')"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "b573eb49-7d18-48dc-a434-9dbad60c8cea", "_uuid": "8f1ec07f6a741d0a8f45318fa57bcc24236b62f5"}}, {"execution_count": null, "source": ["items.head(10)"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "004f3041-fc2d-4e28-abd8-9b0a817c7563", "_uuid": "a3ac18da6d9db1974a44ec1d732fffd8cec77702"}}, {"execution_count": null, "source": ["items['family'].unique()"], "cell_type": "code", "outputs": [], "metadata": {}}, {"execution_count": null, "source": ["item_family = items.groupby(['family', 'class']).item_nbr.size()\n", "item_family.unstack().plot(kind = 'bar', stacked = True, figsize = (13,11), grid = True)"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "5bc3f70d-9fea-4f82-9540-555e9a6f62e0", "_uuid": "eaa65cb6d2f07cdc85eb45f35b5ffc4dd2a942c3"}}, {"execution_count": null, "source": ["plt.hist(items['perishable'],bins = 4)\n", "plt.title(\"count of perishable items\")\n", "plt.xlabel(\"perishable\")\n", "plt.ylabel(\"Count\")"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "a852e906-d499-4de2-9191-ac0914e4da5a", "_uuid": "e92bb1719d7667f7d6ce1b2e1c97b2621b5d8881"}}, {"execution_count": null, "source": ["# Importing the oil data file\n", "oil = pd.read_csv('../input/oil.csv')\n", "oil.describe(include = 'all')"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "4cd27d51-6af3-4843-a904-3d00d1529283", "_uuid": "5e540e41bd91c9e7a4791be164716cf369a2dc25"}}, {"execution_count": null, "source": ["# Replacing the NAN values with the price of oil for the next day\n", "for i in range(0, 1218):\n", "    value = oil['dcoilwtico'][i]\n", "    if np.isnan(oil['dcoilwtico'][i]) == 1:\n", "        value = oil['dcoilwtico'][i+1]\n", "        oil['dcoilwtico'][i] = value"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "c1bbb2e8-733a-44fa-af28-a74592c2fddc", "_uuid": "2f94b5f5fcb70da067fab1fa1da56f296ef3771c"}}, {"execution_count": null, "source": ["oil.describe(include = 'all')"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "298f8ef8-55bb-41e0-8bf5-3d6887cc2381", "_uuid": "d4ab32ace8736c0c4539922946acec3c45f67b0b"}}, {"execution_count": null, "source": ["import datetime\n", "#year = datetime.date.today().year\n", "plt.plot(oil.iloc[:, -1].values, oil.iloc[:, 1].values, color = 'blue')\n", "#plt.plot(X_train, regressor.predict(X_train), color = 'blue')\n", "plt.title('Oil Price trend')\n", "plt.xlabel('Price')\n", "plt.ylabel('Year')\n", "plt.show()"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "0593fc06-ddab-43d9-bdc1-c8bbdbea5925", "_uuid": "cfcc24fee804d4a8cfaa9d84a7c883648067e7af"}}, {"execution_count": null, "source": ["# Importing the stores data file\n", "stores = pd.read_csv('../input/stores.csv')\n", "stores.describe(include = 'all')"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "1ce3b1a6-73de-4ad3-8716-3ac31ce83d50", "_uuid": "24e5d850b5308627cc0ab43e0663cd17901c070b"}}, {"execution_count": null, "source": ["# Stores per state\n", "stores['state'].unique()\n", "state_cluster = stores.groupby(['state', 'cluster']).store_nbr.size()\n", "state_cluster.unstack().plot(kind = 'bar', stacked = True, figsize=(13,11), grid = True)"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "69beeeeb-79e9-417a-938c-2206858a3a1c", "_uuid": "7d60eecb1f82593cbca0089394f13ff1796da3ec"}}, {"execution_count": null, "source": ["plt.style.use('seaborn-white')\n", "city_cluster = stores.groupby(['city','type']).store_nbr.size()\n", "city_cluster.unstack().plot(kind='bar',stacked=True, colormap= 'viridis', figsize=(13,11),  grid=False)"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "074ac4ec-de16-4b67-a458-79965e729547", "_uuid": "7f9d2bfb4033412fbaba4397b6cda5d95d1cc25a"}}, {"execution_count": null, "source": ["plt.style.use('seaborn-white')\n", "city_stores_cluster = stores.groupby(['state', 'city']).store_nbr.size()\n", "city_stores_cluster.unstack().plot(kind='bar',stacked=True, colormap= 'viridis', figsize=(13,11),  grid=False)"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "0d04054f-2c06-4217-b964-cad0b269e64f", "_uuid": "a32d98b3494c8f338241dfde27661db682ad9a87"}}, {"execution_count": null, "source": ["# Importing the transactions data file\n", "transactions = pd.read_csv('../input/transactions.csv')\n", "transactions.describe(include = 'all')"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "025b9b45-a972-45dd-b16f-22b678857ba3", "_uuid": "9008c80b99067714a26b422d7fe0be77ed996850"}}, {"execution_count": null, "source": ["transactions.head(10)"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "7233cf3a-1ff4-4dd3-adba-4a15cc42b4f2", "_uuid": "43606cb4a4c88324b868e8a88fb6c612eeb8ab4c"}}, {"execution_count": null, "source": ["X = transactions.iloc[:, 0:2].values\n", "y = transactions.groupby('date').transactions.sum()\n", "print(y)\n", "plt.hist(y)\n"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "912769c4-afc9-404c-b046-eae321bce04e", "_uuid": "7204869146aa4745980542bd6255a2ba2d684f89"}}, {"execution_count": null, "source": ["train = pd.read_csv(\"../input/train.csv\", nrows=30000, parse_dates=['date'])\n", "train.head(10)"], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "100daf5a-055a-4b22-855c-a8581eb8fd0f", "_uuid": "93a17b87daafa7f89bc9193b33de9fa5aff9eaac"}}, {"execution_count": null, "source": ["# splitting the date into year month and date\n", "next(train)\n", "x = [date  for date in train]\n", "for date_str in x:\n", "    year, month, day = date_str.split('-')\n", "    print(year, month, day)\n", "    "], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "1e7eed53-a246-4e1d-9ec6-e79730df4e6e", "_uuid": "cfbaebe22d142335b53ad42e18adced80318e03f"}}, {"execution_count": null, "source": [], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "ca73eef6-1267-4e66-94b7-f1632c3c72d0", "_uuid": "42612208b0cb65bcc6f5c660f379fcef458f9c74", "collapsed": true}}, {"execution_count": null, "source": [], "cell_type": "code", "outputs": [], "metadata": {"_cell_guid": "e80772ca-585e-41aa-bef1-ab8e59c46303", "_uuid": "eede6521494d5f64e1c5cb9343cedda1a2984896", "collapsed": true}}], "metadata": {"language_info": {"pygments_lexer": "ipython3", "nbconvert_exporter": "python", "name": "python", "codemirror_mode": {"name": "ipython", "version": 3}, "version": "3.6.3", "mimetype": "text/x-python", "file_extension": ".py"}, "kernelspec": {"name": "python3", "language": "python", "display_name": "Python 3"}}}