Title: Exponential smoothing function in python for different groups of time series data
Tags: python;time-series
Question: How to create exponential smoothening function(SES having different trends, fluctuations for each sector)  when no of sectors are more than 50 in python?
Sector
Demand
Sector 1
23-07-2021
Sector 1
24-07-2021
Sector 1
25-07-2021
Sector 1
26-07-2021
Sector 1
23-07-2021
Sector 1
25-07-2021
Sector 1
26-07-2021
Sector 1
27-07-2021
Sector 2
19-07-2021
Sector 2
20-07-2021
Sector 2
26-07-2021
Sector 2
28-07-2021
Sector 2
29-07-2021
Sector 2
30-07-2021
Sector 2
31-07-2021
Sector 2
1-08-2021
The function should contain checking of trends and seasonality, estimate the trend and seasonality and then converting to stationary  series only for non stationary data.
Comment: Where are you getting stuck? Can you show some code, and further restrict the scope of your question? Right now you're asking a great many questions in one: how to detect (non)stationarity, how to account for it, how to model seasonal/trend components in a time series, and how to fit a model to your subset of data that somehow accounts for all this. What do you intend to use the model for?

Comment: what do you mean by "no of sectors are more than 50"?

Comment: Demand for different sectors across time. I want to apply exponential smoothing on demand for each sector where no of sectors or you can destination is more than 50.  Looping over each sector, checking trend and sseasonality for

Comment: Looping over each sector, checking trend and seasonality, appling time series forecasting method like exponential smoothing and then checking weightage error.


Here is another answer: Ok so a few issues.
Your data is not monotonic which will cause you issues when trying to incorporate seasonality
You haven't supplied enough information/data to make any meaningful analysis on seasonality. How many periods are you tracking? What do you consider to be a &quot;season&quot;?
My suggestion would be to do a Triple ES (Holt-Winters) using statsmodels
from statsmodels.tsa.holtwinters import ExponentialSmoothing
df = pd.read_clipboard()
# removing duplicated dates
data = data.drop(df.index[[4,5,6,8,9,10,15]])
def triple_smoothing(g):
print(f'Creating model for: {g.Sector.iloc[0]}')
model = ExponentialSmoothing(g['Demand'], trend=&quot;add&quot;, seasonal=&quot;add&quot;, seasonal_periods=2)
fit = model.fit()
pred = fit.forecast(7)
print()
print('Training data...')
print('-----------------------------------')
print(g['Demand'])
print()
print('Forecasted...')
print('-----------------------------------')
print(pred)
print('-----------------------------------')
print()
data['Time'] = pd.to_datetime(data['Time'])
data.index = pd.DatetimeIndex(data['Time']).to_period('D')
data.groupby('Sector').apply(triple_smoothing)
Sector 1:
Creating model for: Sector 1
Training data...
-----------------------------------
2021-07-23    100
2021-07-24    105
2021-07-25    200
2021-07-26    206
2021-07-27    460
Freq: D, Name: Demand, dtype: int64
Forecasted...
-----------------------------------
2021-07-28    401.798180
2021-07-29    581.687497
2021-07-30    565.979365
2021-07-31    745.868683
2021-08-01    730.160551
2021-08-02    910.049868
2021-08-03    894.341736
Freq: D, dtype: float64
-----------------------------------
Sector 2:
Creating model for: Sector 2
Training data...
-----------------------------------
2021-07-28    2060
2021-07-29    3100
2021-07-30    3605
2021-07-31    3910
Freq: D, Name: Demand, dtype: int64
Forecasted...
-----------------------------------
2021-08-01    4558.890106
2021-08-02    5289.477706
2021-08-03    (438)465-3983
2021-08-04    6458.943383
2021-08-05    (438)465-3983
2021-08-06    (438)465-3983
2021-08-07    (438)465-3983
Freq: D, dtype: float64
-----------------------------------
Obviously these are very inaccurate since they both have <10 observations.
Add more data and adjust/train model for better accuracy

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:07/23/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><time-series>', 'Title': 'Exponential smoothing function in python for different groups of time series data', 'ViewCount': 401, 'id': 68502139, 'user_AboutMe': None, 'user_AccountId': 21280356.0, 'user_DisplayName': 'Ria Sadhu', 'user_Reputation': 11.0, 'user_Views': 6.0, 'user_id': 15971348.0}}