Last active
April 29, 2021 07:21
-
-
Save therealnaveenkamal/4c4a049f2b533f17f06ef92c22e06e40 to your computer and use it in GitHub Desktop.
This Code Snippet Plots the Trend and the Seasonality of the Time Series data
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 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") | |
variable = 'Close' | |
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15, 6)) | |
sns.boxplot(df['Year'], df[variable], ax=ax[0]) | |
ax[0].set_title('Year-wise Box Plot\n(The Trend)', | |
fontsize = 20, | |
loc='center', | |
fontdict=dict(weight='bold')) | |
ax[0].set_xlabel('Year') | |
ax[0].set_ylabel('Price') | |
sns.boxplot(df['Month'], df[variable], ax=ax[1]) | |
ax[1].set_title('Month-wise Box Plot\n(The Seasonality)', | |
fontsize = 20, | |
loc='center', | |
fontdict=dict(weight='bold')) | |
ax[1].set_xlabel('Month') | |
ax[1].set_ylabel('Price') | |
fig.autofmt_xdate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment