Apply time series decomposition to your dataset
You will now perform time series decomposition on multiple time series. You can achieve this by leveraging the Python dict
ionary to store the results of each time series decomposition.
In this exercise, you will initialize an empty dictionary with a set of curly braces, {}
, use a for
loop to iterate through the columns of the DataFrame and apply time series decomposition to each time series. After each time series decomposition, you place the results in the dictionary by using the command my_dict[key] = value
, where my_dict
is your dictionary, key
is the name of the column/time series, and value
is the decomposition object of that time series.
This exercise is part of the course
Visualizing Time Series Data in Python
Exercise instructions
- Initialize an empty dictionary called
jobs_decomp
. - Extract the column names of the
jobs
DataFrame and place the results in a list calledjobs_names
. - Iterate through each column in
jobs_names
and apply time series decomposition to that time series. Place the results in thejobs_decomp
dictionary, where the column name is the key, and the value is the decomposition of the time series you just performed.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Initialize dictionary
____
# Get the names of each time series in the DataFrame
____ = ____
# Run time series decomposition on each time series of the DataFrame
for ts in ____:
ts_decomposition = sm.tsa.seasonal_decompose(____)
jobs_decomp[ts] = ____