diff --git a/CHANGELOG.md b/CHANGELOG.md index c991bf4a..ca57189e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## pytimetk version 0.1.0.9000 (in development) +New Functions: + +- `augment_expanding()` +- `get_frequency()` + ## pytimetk version 0.1.0 (2023-10-02) Initial release. This release includes the following features: diff --git a/src/pytimetk/core/anomaly.py b/src/pytimetk/core/anomaly.py new file mode 100644 index 00000000..3c2e6a62 --- /dev/null +++ b/src/pytimetk/core/anomaly.py @@ -0,0 +1,26 @@ +import pandas as pd + +from pytimetk import ts_summary + +from statsmodels.tsa.seasonal import STL + +def stl_decompose(data, date_column, value_column, freq, trend, **kwargs): + + summary_df = ts_summary(data, date_column) + + # Decompose the time series + stl = STL(data[value_column], freq=freq, **kwargs) + res = stl.fit() + + # Build the dataframe containing the decomposed components + df = pd.DataFrame({ + 'date': data[date_column], + 'value': data[value_column], + 'trend': res.trend, + 'seasonal': res.seasonal, + 'residual': res.resid + }) + + return df + + \ No newline at end of file