Skip to content

Instantly share code, notes, and snippets.

@kperry2215
Created July 20, 2019 02:36
Show Gist options
  • Save kperry2215/f9fc8ed4a64073e15f197c049086c794 to your computer and use it in GitHub Desktop.
Save kperry2215/f9fc8ed4a64073e15f197c049086c794 to your computer and use it in GitHub Desktop.
def decompose_time_series(series):
"""
Decompose a time series and plot it in the console
Arguments:
series: series. Time series that we want to decompose
Outputs:
Decomposition plot in the console
"""
result = seasonal_decompose(series, model='additive')
result.plot()
pyplot.show()
#Execute in the main block
#Convert the Date column into a date object
electricity_df['Date']=pd.to_datetime(electricity_df['Date'])
#Set Date as a Pandas DatetimeIndex
electricity_df.index=pd.DatetimeIndex(electricity_df['Date'])
#Decompose the time series into parts
decompose_time_series(electricity_df['Electricity_Price'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment