<jupyter_start><jupyter_text>Load Time Series<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pylab as plt
%matplotlib inline
from matplotlib.pylab import rcParams
rcParams['figure.figsize'] = 15, 6
filename = './data/energy-spot-price.tsv'<jupyter_output><empty_output><jupyter_text>Load data<jupyter_code>data = pd.read_csv(filename, delimiter="\t")
print(data.head())
print('\n Data Types:')
print(data.dtypes)<jupyter_output>Date  Price
0  01/10/2014  32.78
1  01/10/2014  32.51
2  01/10/2014  32.01
3  01/10/2014  31.58
4  01/10/2014  32.13

 Data Types:
Date      object
Price    float64
dtype: object<jupyter_text>Load data, parse date/time<jupyter_code>dateparse = lambda dates: pd.datetime.strptime(dates, '%d/%m/%Y')
data = pd.read_csv(filename, parse_dates=['Date'], index_col='Date', date_parser=dateparse, delimiter="\t")

print(data.head())
print('\n Data Types:')
print(data.dtypes)
data.index<jupyter_output><empty_output><jupyter_text>Subsetting by dates<jupyter_code>ts = data['Price'] 
ts.head(10)
ts['2014-11-01'][0:10]
ts['2014-11-01' : '2014-11-02']
ts['2014-11']
plt.plot(ts)<jupyter_output><empty_output><jupyter_text>Check Stationary or Non-Starionary<jupyter_code>## From: https://www.analyticsvidhya.com/blog/2016/02/time-series-forecasting-codes-python/
from statsmodels.tsa.stattools import adfuller
def test_stationarity(timeseries):
    
    #Determing rolling statistics
    rolmean = pd.rolling_mean(timeseries, window=60)
    rolstd = pd.rolling_std(timeseries, window=60)

    #Plot rolling statistics:
    orig = plt.plot(timeseries, color='blue',label='Original')
    mean = plt.plot(rolmean, color='red', label='Rolling Mean')
    std = plt.plot(rolstd, color='black', label = 'Rolling Std')
    plt.legend(loc='best')
    plt.title('Rolling Mean & Standard Deviation')
    plt.show(block=False)
    
    #Perform Dickey-Fuller test:
    print ('Results of Dickey-Fuller Test:')
    dftest = adfuller(timeseries, autolag='AIC')
    dfoutput = pd.Series(dftest[0:4], index=['Test Statistic','p-value','#Lags Used','Number of Observations Used'])
    for key,value in dftest[4].items():
        dfoutput['Critical Value (%s)'%key] = value
    print(dfoutput)
test_stationarity(ts)
ts_log = np.log(ts)
plt.plot(ts_log)
moving_avg = pd.rolling_mean(ts_log,60)
plt.plot(ts_log)
plt.plot(moving_avg, color='red')
ts_log_moving_avg_diff = ts_log - moving_avg
ts_log_moving_avg_diff.head(12)
ts_log_moving_avg_diff.dropna(inplace=True)
test_stationarity(ts_log_moving_avg_diff)
expwighted_avg = pd.ewma(ts_log, halflife=12)
plt.plot(ts_log)
plt.plot(expwighted_avg, color='red')
ts_log_ewma_diff = ts_log - expwighted_avg
test_stationarity(ts_log_ewma_diff)<jupyter_output>C:\local\Anaconda3-4.1.1-Windows-x86_64\envs\cntk-py34\lib\site-packages\ipykernel\__main__.py:6: FutureWarning: pd.rolling_mean is deprecated for Series and will be removed in a future version, replace with 
	Series.rolling(center=False,window=60).mean()
C:\local\Anaconda3-4.1.1-Windows-x86_64\envs\cntk-py34\lib\site-packages\ipykernel\__main__.py:7: FutureWarning: pd.rolling_std is deprecated for Series and will be removed in a future version, replace with 
	Series.rolling(center=False,window=60).std()
{'fraction_non_alphanumeric': 0.1391465677179963, 'fraction_numerical': 0.04638218923933209, 'mean_word_length': 5.7677824267782425, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '376745', 'license': 'MIT', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1219, 'n_words': 216, 'path': 'Time Series Utilities.ipynb', 'repo_name': 'ryubidragonfire/cntk', 'size': '3234'}