Created
April 29, 2021 10:51
-
-
Save therealnaveenkamal/7b4da00cd290f95f799cb07b0c49ef5c to your computer and use it in GitHub Desktop.
This Code Snippet is used to decompose Time Series data into its respective components.
This file contains 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 pandas_datareader import data | |
import statsmodels.api as sm | |
from pylab import rcParams | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
df = data.DataReader("RELIANCE.NS", | |
data_source = "yahoo", | |
start = "2010-01-28", | |
end = "2020-12-28") | |
df['Date'] = pd.to_datetime(df.index) | |
df['Year'] = df['Date'].dt.year | |
df['Month'] = df['Date'].dt.month | |
plt.style.use("fivethirtyeight") | |
y = df[['Date','Open']].copy() | |
y.set_index('Date', inplace=True) | |
y.index = pd.to_datetime(y.index) | |
y = y.resample("1M").mean() | |
rcParams['figure.figsize'] = 15, 12 | |
rcParams['axes.labelsize'] = 20 | |
rcParams['ytick.labelsize'] = 16 | |
rcParams['xtick.labelsize'] = 16 | |
decomposition = sm.tsa.seasonal_decompose(y, model='multiplicative', freq = 12) | |
decomp = decomposition.plot() | |
decomp.suptitle('Open decomposition', fontsize=22) | |
print(decomp.get_size_inches) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment