{"nbformat_minor": 1, "nbformat": 4, "cells": [{"cell_type": "code", "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", "import seaborn as sns \n", "import matplotlib.pyplot as plt \n", "%matplotlib inline\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", "\n", "\n", "# Any results you write to the current directory are saved as output."], "execution_count": null, "metadata": {"_cell_guid": "b866200b-59cb-4b9c-b847-61087293b05e", "scrolled": true, "_uuid": "6ccb1b7c93f2fa9f64469e21dc252c827dce0a34"}}, {"cell_type": "code", "outputs": [], "source": ["df_train = pd.read_csv(\"../input/train.csv\",parse_dates=[\"date\"],index_col=\"id\",dtype={\"store_nbr\":np.int32,\"unit_sales\":np.float64})"], "execution_count": null, "metadata": {"_cell_guid": "9a29dc54-6ab5-42c7-9a63-e0c29b85cae8", "_uuid": "324341de262d4a258f538649554ed4878945e1f7"}}, {"cell_type": "code", "outputs": [], "source": ["df_stores = pd.read_csv(\"../input/stores.csv\")"], "execution_count": null, "metadata": {"_cell_guid": "e1cab29f-9949-4daf-9926-7f25a77c9adf", "collapsed": true, "_uuid": "425270219e077968ad1f925689ca24cc7724c032"}}, {"cell_type": "code", "outputs": [], "source": ["df_items = pd.read_csv(\"../input/items.csv\")"], "execution_count": null, "metadata": {"_cell_guid": "bd315bd2-cdfb-47ad-b761-50750bee1e70", "collapsed": true, "_uuid": "d9c90b3fcac8e8948699c30265737c0aa8885355"}}, {"cell_type": "code", "outputs": [], "source": ["df_transactions = pd.read_csv(\"../input/transactions.csv\",parse_dates=[\"date\"])"], "execution_count": null, "metadata": {"_cell_guid": "79cf2338-e667-4cd9-a9e8-8ae4cc974b23", "collapsed": true, "_uuid": "d37e858927648d47118b7d7ba65631acbb49a0c1"}}, {"cell_type": "code", "outputs": [], "source": ["df_holidays = pd.read_csv(\"../input/holidays_events.csv\",parse_dates=[\"date\"])"], "execution_count": null, "metadata": {"_cell_guid": "248bbd61-48c3-4518-bd6c-b3d68a28d9c4", "collapsed": true, "_uuid": "56b1b61edcea633253ce0f310174269a21e974b4"}}, {"cell_type": "code", "outputs": [], "source": ["holidays = pd.get_dummies(df_holidays[\"type\"])\n", "locale = pd.get_dummies(df_holidays['locale'],drop_first=True)"], "execution_count": null, "metadata": {"_cell_guid": "29a776f7-2360-472b-b3bc-5873152c4e43", "_uuid": "53962da5e1c014859bcf991ddba8f4af11694aaf"}}, {"cell_type": "code", "outputs": [], "source": ["df_holidays = pd.concat([df_holidays,holidays,locale],axis=1)"], "execution_count": null, "metadata": {"_cell_guid": "51eea8b6-c456-45c1-ae53-bbba67391ab2", "collapsed": true, "_uuid": "b4ce2ea58bf6e2e6626273185f9a765ff2dbed7f"}}, {"cell_type": "code", "outputs": [], "source": ["df_holidays.drop(\"type\",axis=1,inplace=True)\n", "df_holidays.drop(\"description\",axis=1,inplace=True)"], "execution_count": null, "metadata": {"collapsed": true}}, {"cell_type": "code", "outputs": [], "source": ["df_holidays.drop(\"locale\",axis=1,inplace=True)"], "execution_count": null, "metadata": {"collapsed": true}}, {"cell_type": "code", "outputs": [], "source": ["df_holidays = pd.concat([df_holidays,locale],axis=1)"], "execution_count": null, "metadata": {"collapsed": true}}, {"cell_type": "code", "outputs": [], "source": ["df_holidays['transferred'] = df_holidays['transferred'].astype(\"bool\")"], "execution_count": null, "metadata": {}}, {"cell_type": "code", "outputs": [], "source": ["df_holidays['transferred'] = df_holidays['transferred'].map({False:0,True:1})"], "execution_count": null, "metadata": {"collapsed": true}}, {"cell_type": "code", "outputs": [], "source": ["df_holidays.head()"], "execution_count": null, "metadata": {}}, {"cell_type": "code", "outputs": [], "source": ["# locale_names = pd.get_dummies(df_holidays['locale_name'],drop_first=True)\n", "# df_holidays = pd.concat([df_holidays,locale_names],axis=1)"], "execution_count": null, "metadata": {}}, {"cell_type": "code", "outputs": [], "source": ["df_train_2017 = df_train[df_train['date'].dt.year == 2017]"], "execution_count": null, "metadata": {}}, {"cell_type": "code", "outputs": [], "source": ["df_train_2016 = df_train[df_train['date'].dt.year == 2016]"], "execution_count": null, "metadata": {"collapsed": true}}, {"cell_type": "code", "outputs": [], "source": ["df_train_2015 = df_train[df_train['date'].dt.year == 2015]"], "execution_count": null, "metadata": {"collapsed": true}}, {"cell_type": "code", "outputs": [], "source": ["df_train_2017 = df_train_2017.merge(df_holidays,how=\"left\",on=\"date\")"], "execution_count": null, "metadata": {"collapsed": true}}, {"cell_type": "code", "outputs": [], "source": ["df_train_2017.head()"], "execution_count": null, "metadata": {}}, {"cell_type": "code", "outputs": [], "source": ["df_items.head()"], "execution_count": null, "metadata": {}}, {"cell_type": "code", "outputs": [], "source": ["df_items.groupby([\"perishable\",\"family\"]).size()"], "execution_count": null, "metadata": {}}, {"cell_type": "code", "outputs": [], "source": ["home_dict = {\"HOME AND KITCHEN I\":\"home\",\"HOME AND KITCHEN II\":\"home\",\"CLEANING\":\"home\"}\n", "food_non_perishable_dict = {\"GROCERY I\":\"non_perishable_food\",\"GROCERY II\":\"non_perishable_food\",\"FROZEN FOODS\":\"non_perishable_food\"}\n", "clothing_dict = {\"LADIESWEAR\":\"women_wear\",\"LINGERIE\":\"women_wear\"}\n", "personal_dict = {\"PERSONAL CARE\":\"personal\",\"BEAUTY\":\"personal\",\"BABY CARE\":\"personal\",\"HOME CARE\":\"personal\",\"CELEBRATION\":\"personal\"}\n", "others_dict = {\"BOOKS\":\"others\",\"MAGAZINES\":\"others\",\"SCHOOL AND OFFICE SUPPLIES\":\"others\",\"PET SUPPLIES\":\"others\",\"LAWN AND GARDEN\":\"others\"}\n", "appliance_dict = {\"HOME APPLIANCES\":\"appliance\",\"PLAYERS AND ELECTRONICS\":\"appliance\",\"HARDWARE\":\"appliance\"}\n", "drinks_dict = {\"BEVERAGES\":\"drink\",\"LIQUOR,WINE,BEER\":\"drink\"}"], "execution_count": null, "metadata": {"collapsed": true}}, {"cell_type": "code", "outputs": [], "source": ["df_items['family'].value_counts()"], "execution_count": null, "metadata": {}}, {"cell_type": "code", "outputs": [], "source": [], "execution_count": null, "metadata": {"collapsed": true}}], "metadata": {"kernelspec": {"name": "python3", "language": "python", "display_name": "Python 3"}, "language_info": {"mimetype": "text/x-python", "pygments_lexer": "ipython3", "file_extension": ".py", "codemirror_mode": {"version": 3, "name": "ipython"}, "nbconvert_exporter": "python", "version": "3.6.3", "name": "python"}}}