{"nbformat": 4, "metadata": {"language_info": {"file_extension": ".py", "mimetype": "text/x-python", "pygments_lexer": "ipython3", "name": "python", "version": "3.6.3", "nbconvert_exporter": "python", "codemirror_mode": {"name": "ipython", "version": 3}}, "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}}, "cells": [{"outputs": [], "metadata": {"_uuid": "39c27ef5dc083ff096c1a5b5eaec2c2a8d156847", "_cell_guid": "b49f88ea-e95d-4b84-8f3a-1fde166fda8f"}, "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", "\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"}, {"outputs": [], "metadata": {"_uuid": "55235df16d9239b18bf4d45a3312b726630ee306", "_cell_guid": "b56d4030-835e-4c18-8b35-053070e7c286"}, "execution_count": null, "source": ["#print the first five lines and each col data class\n", "with open('../input/train.csv') as f:\n", "    f_csv = pd.read_csv(f)\n", "    #print(f_csv.head())\n", "print(f_csv.dtypes)"], "cell_type": "code"}, {"outputs": [], "metadata": {"_uuid": "650c23ca3d71001f34cc63746ef7f30d72bfb7ef", "_cell_guid": "d4ce04bb-5959-4f2e-9a6c-87e7dc13c8d0"}, "execution_count": null, "source": ["# statistic the train.csv contain how many days data, how many stores and how many items\n", "date = np.unique(f_csv['date'])\n", "store_nbr = np.unique(f_csv['store_nbr'])\n", "item_nbr = np.unique(f_csv['item_nbr'])\n", "unit_sales = np.unique(f_csv['unit_sales'])\n", "print(\"%d days, %d stores, %d items\" % (len(date),len(store_nbr),len(item_nbr)))"], "cell_type": "code"}, {"outputs": [], "metadata": {"_uuid": "d1ce5242c248ead2add33a8e0a85a0e8554ccb30", "_cell_guid": "b67f77e1-60fd-459e-a300-d229f5f3ee8e"}, "execution_count": null, "source": ["#Nan to -1\n", "item_id_dict = {}\n", "for item in item_nbr:\n", "    item_id = np.where(f_csv['item_nbr']==item)\n", "    item_id_dict[str(item)] = item_id\n", "tmp_onpromotion = np.zeros(len(f_csv['onpromotion']))\n", "tmp_onpromotion[np.where(f_csv['onpromotion'] != f_csv['onpromotion'])] = -1\n", "tmp_onpromotion[np.where(f_csv['onpromotion'] is True)] = 1\n", "tmp_onpromotion[np.where(f_csv['onpromotion'] is False)] = 0\n", "print(\"before trans:\", f_csv['onpromotion'])\n", "print(\"after trans:\",tmp_onpromotion)"], "cell_type": "code"}, {"outputs": [], "metadata": {"_uuid": "0479a0b2c39bb343f356a2a6c35c0ebd3b50ce67", "collapsed": true, "_cell_guid": "641f0a5f-1a64-42f3-912a-335e57f91acf"}, "execution_count": null, "source": [], "cell_type": "code"}], "nbformat_minor": 1}