Path: blob/master/lessons/lesson_16/solution-code/05_independent_practice_solutions.ipynb
1904 views
Kernel: Python 2
Time Series Independent Practice
In [18]:
Walmart Sales Data
For this independent practice, we'll analyze Walmart's weekly sales data over a two-year period from 2010 to 2012.
The data set is again separated by store and department, but we'll focus on analyzing one store for simplicity.
The data include:
Store
: The store number.Dept
: The department number.Date
: The week.Weekly_Sales
: Sales for the given department in the given store.IsHoliday
: Whether the week is a special holiday week.
1) Preprocess the data using Pandas.
Load the data.
Convert the
Date
column to adatetime
object.Set
Date
as the index of the DataFrame.
In [19]:
In [20]:
Out[20]:
In [21]:
Out[21]:
Store int64
Dept int64
Date object
Weekly_Sales float64
IsHoliday bool
dtype: object
In [22]:
In [23]:
Out[23]:
Store int64
Dept int64
Date datetime64[ns]
Weekly_Sales float64
IsHoliday bool
dtype: object
In [24]:
In [25]:
Out[25]:
2) Filter the DataFrame to Store 1 sales and aggregate over departments to compute the total weekly sales per store. Store this in a new DataFrame.
In [26]:
Out[26]:
/Users/nicholebennett/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: FutureWarning: how in .resample() is deprecated
the new syntax is .resample(...).sum()
"""Entry point for launching an IPython kernel.
In [27]:
Out[27]:
3) Plot the rolling mean for Weekly_Sales
. What general trends do you observe?
In [28]:
Out[28]:
<matplotlib.axes._subplots.AxesSubplot at 0x1c0dd14860>
4) Compute the 1
, 13
, and 52
autocorrelations for Weekly_Sales
and/or create an autocorrelation plot.
In [33]:
Out[33]:
Autocorrelation 1: 0.302158279411
Autocorrelation 13: 0.10169228502
Autocorrelation 52: 0.895376029478
In [30]:
Out[30]:
/Users/nicholebennett/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:3: FutureWarning: 'pandas.tools.plotting.autocorrelation_plot' is deprecated, import 'pandas.plotting.autocorrelation_plot' instead.
This is separate from the ipykernel package so we can avoid doing imports until
<matplotlib.axes._subplots.AxesSubplot at 0x10ac317b8>
In [40]:
Out[40]:
5) Create a decomposition plot for the Store 1 sales data.
In [35]:
Out[35]:
6) Based on the analyses above, what can we deduce about this time series?
In [41]:
In [ ]: