{"nbformat_minor": 1, "cells": [{"execution_count": null, "cell_type": "code", "metadata": {"_uuid": "f7625e65175e2d5404be814e612d5cdb32201efa", "_cell_guid": "77a12f6d-3cdd-446e-ae87-6c9bc9a0348b"}, "outputs": [], "source": ["#python using 2.7\n", "#this karnel will return for you a table that has the average unit_sales per week.\n", "#Moreover it will return the average of a certain week(for all years) for a specific store\n", "#those tables can help you develop a moving average forecast by week.\n", "\n", "\n", "import csv\n", "import datetime\n", "import pandas as pd\n", "\n", "train = pd.read_csv('train.csv')\n", "#converting to datetime\n", "train['date']= pd.to_datetime(train.date)\n", "#adding yerar and week \n", "train['week'] = train['date'].dt.week\n", "train['year'] = train['date'].dt.year\n", "\n", "#getting the mean for a week in each year\n", "weekly_beh_yearly = train.groupby(['item_nbr','year','week','store_nbr'],as_index= False) ['unit_sales'].mean()\n", "#getting the mean for a week along all years\n", "weekly_beh_avr = train.groupby(['item_nbr', 'week','store_nbr'],as_index=False)['unit_sales'].mean()\n", "\n", "#this way you will deal with data based on weeks instead of days.\n", "\n"]}], "nbformat": 4, "metadata": {"language_info": {"nbconvert_exporter": "python", "version": "3.6.3", "name": "python", "codemirror_mode": {"name": "ipython", "version": 3}, "pygments_lexer": "ipython3", "file_extension": ".py", "mimetype": "text/x-python"}, "kernelspec": {"language": "python", "display_name": "Python 3", "name": "python3"}}}