Created
March 23, 2020 03:02
-
-
Save lylayang/56e639bd8444e35ebb7ca5970c597299 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from statsmodels.tsa.stattools import adfuller | |
df1=df.resample('D', how=np.mean) | |
def test_stationarity(timeseries): | |
rolmean = timeseries.rolling(window=30).mean() | |
rolstd = timeseries.rolling(window=30).std() | |
plt.figure(figsize=(14,5)) | |
sns.despine(left=True) | |
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() | |
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(df1.Spend.dropna()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment