Time Series Analysis Fresco Play Hands on Solution

Learn how to solve a Time Series problem using Python, including Unsampling, Downsampling, Resampling, TimeZones, Plotting, Trends, and Patterns

Lab 1: Welcome to Time Series Analysis - List out all the values.

Time Series Analysis - List out all the values.

Solution 1:

# Task 1: Run the below to import the data for this hands-on,
#         The data contains All stocks in the S-P 500 index, and their historical prices for the year 2011

import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()


# Task 2: Run the below cell to filter the closing price related to stock 'AA'

closeTS = dataFrame[(dataFrame.stock == 'AA')].close.str.replace('$',' ').astype(float)
#print(closeTS)

# Task: 3 Using the data filtered in the above step list all the closing price from Jan to March,
#         assign the resulting series to variable 'close_AA'

### Start code here
close_AA = closeTS.loc['2011-01-01': '2011-03-31']
### End code(approx 1 line)

# Task 4: Run the below cells to save your answers

from test_ts_listvalues import values
values.save_ans1(close_AA)

Lab 2: Welcome to Time Series Analysis - Resampling month wise.

Time Series - Resampling month wise.

Solution 2:

# Task 1: Run the below to import the data for this hands-on,
#         The data contains All stocks in the S-P 500 index, and their historical prices for the year 2011

import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()


# Task 2: Run the below cell to filter the closing price related to stock 'AA'

closeTS = dataFrame[(dataFrame.stock == 'AA')].close.str.replace('$',' ').astype(float)
#print(closeTS)



# Task 3: Downsample the data filtered in the above step month wise and fill the max value of closing price for each month
#         assign the resulting series to variable 'downsample'

###Start code here

downsample = closeTS.resample('M').max()

#print(downsample)
###End code(approx 1 line)


# Task 4: Run the below cells to save your answers
from test_ts_resample_month import values
values.save_ans1(downsample)

Lab 3: Welcome to Time Series Analysis - Resampling day wise and Interpolate

Time series - Resampling day wise and Interpolate

Solution 3:

# Task 1: Run the below to import the data for this hands-on,
#         The data contains All stocks in the S-P 500 index, and their historical prices for the year 2011

import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()


# Task 2: Run the below cell to filter the closing price related to stock 'AA'

closeTS = dataFrame[(dataFrame.stock == 'AA')].close.str.replace('$',' ').astype(float)
#print(closeTS)


# Task 3: upsample the data filtered in the above step day wise and perform interpolation to forward fill the first two 'Nan' values.
#       return the first 10 samples of upsampled data to variable 'upsample'

###Start code here
upsample = closeTS.resample('D' , fill_method='ffill', limit=2).head(10)
#print(upsample)
###End code(approx 1 line)


# Task 4: Run the below cells to save your answers
from test_ts_resample_month import values
values.save_ans1(upsample)

Lab 4: Time series - WMT stock

Welcome to Time Series Analysis - WMT stock

Solution 4:

# Task 1
# Run the below to import the data for this hands-on
# The data contains all stocks in the S&P 500 index, and their historical prices for the year 2011
# Dataset : http://archive.ics.uci.edu/ml/machine-learning-databases/00312/dow_jones_index.zip

import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()

# Task 2:
# Run the below cell to filter the opening price related to stock 'WMT'.The sample is returned to variable 'open_WMT_Ts'
open_WMT_Ts = dataFrame[(dataFrame.stock == 'WMT')].open.str.replace('$',' ').astype(float)
open_WMT_Ts.head()

# Task 3:
# from statsmodels import adfuller method
###Start code here
from statsmodels.tsa.stattools import adfuller
###End code

# Task 4:
# perform stationarity check on WMT opening price using adfuller method and return the result to variable 'tsResult'
###Start code here
tsResult = adfuller(open_WMT_Ts)
###End code

# Task 5: Run the Cell.
print('ADF Statistic: %f' % tsResult[0])
print('p-value: %f' % tsResult[1])
for key, value in tsResult[4].items():
    print('\t%s: %.3f' % (key, value))

# Task 6:
# Find the value of ADF Statistic from the above test result and assign it to variable ADF_stat
ADF_stat = float(tsResult[0])
type(ADF_stat)

# Task 7:
# Run the below cells to save your answers
from test_ts_wmt import values
values.save_ans1(ADF_stat)

Lab 5: Welcome to Time Series Analysis - XOM stock

Time series - XOM stock

Solution 5: Time series - XOM stock

# Task 1
# Run the below to import the data for this hands-on
# The data contains all stocks in the S&P 500 index, and their historical prices for the year 2011
# Dataset : http://archive.ics.uci.edu/ml/machine-learning-databases/00312/dow_jones_index.zip

import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()

# Task 2:
# Run the below cell to filter the closing price related to stock 'XOM'. The sample is returned to variable 'close_XOM_Ts'
close_XOM_Ts = dataFrame[(dataFrame.stock == 'XOM')].close.str.replace('$',' ').astype(float)
close_XOM_Ts.head()

# Task 3:
# from statsmodels import adfuller method
###Start code here
from statsmodels.tsa.stattools import adfuller
###End code

# Task 4:
# perform stationarity check on XOM closing price using adfuller method and return the result to variable 'tsResult'
###Start code here
tsResult = adfuller(close_XOM_Ts)
###End code

# Task 5: Run the Cell.
print('ADF Statistic: %f' % tsResult[0])
print('p-value: %f' % tsResult[1])
for key, value in tsResult[4].items():
    print('\t%s: %.3f' % (key, value))

# Task 6:
# Find the value of ADF Statistic from the above test result and assign it to variable ADF_stat
ADF_stat = float(tsResult[0])
type(ADF_stat)

# Task 7:
# Run the below cells to save your answers
from test_ts_wmt import values
values.save_ans1(ADF_stat)



About the Author

I'm a professor at National University's Department of Computer Science. My main streams are data science and data analysis. Project management for many computer science-related sectors. Next working project on Al with deep Learning.....

تعليق واحد

  1. Time series - Resampling day wise and Interpolate

    ###Start code here
    upsample = closeTS.resample('D' ).ffill(limit=2).head(10)
    ###End code(approx 1 line)
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.