Ravindra BagaleCourses & study guides मराठी Track your progress

65. How to Forecast Sales with Time Series in Python (pandas and sklearn)

65.2 What Is a Time Series (Trend, Season, Noise)

Why. If you only learn one formula, you miss why Diwali months jump. Trend, season and noise explain the shape.

What.

  • Trend — slow rise or fall over years.
  • Season — a pattern that repeats (festivals, weekends, Q4).
  • Noise — leftover bumps that have no clean story.
1. Past months in order (time series)2. Spot trend + season + noise3. Fit a simple forecast method4. Predict next months + check MAE/MAPE
Past months → pattern → method → forecast (read top to bottom)

How.

Read a series with your eyes first

  1. Plot month on X and the value on Y.
  2. Ask: is it rising overall? (trend)
  3. Ask: do the same months repeat high/low? (season)
  4. Accept leftover wiggles as noise.
  5. Only then pick a method.

Worked example A — Rising trend in IT SaaS (₹).

Dataset note: fictional Nimbus Soft (Pune) quarterly MRR. 6 rows. Columns: quarter, mrr_inr.

import pandas as pd

saas = pd.DataFrame({
    "quarter": ["2025-Q1", "2025-Q2", "2025-Q3", "2025-Q4", "2026-Q1", "2026-Q2"],
    "mrr_inr": [850000, 920000, 990000, 1100000, 1180000, 1250000],
})
print(saas)
print("Change Q1→Q2 2026:", saas["mrr_inr"].iloc[-1] - saas["mrr_inr"].iloc[-2])

Output you should see.

  quarter  mrr_inr
0 2025-Q1   850000
1 2025-Q2   920000
2 2025-Q3   990000
3 2025-Q4  1100000
4 2026-Q1  1180000
5 2026-Q2  1250000
Change Q1→Q2 2026: 70000

What it means. Clear upward trend. A flat “last value” forecast still works short-term, but lag + trend features help more.

Worked example B — Festival season in Mauli sales.

import pandas as pd

df = pd.read_csv("mauli_monthly_sales.csv", parse_dates=["month"])
df["month_num"] = df["month"].dt.month
print(df.groupby("month_num")["sales_inr"].mean().round(0).astype(int))

What it means. Some calendar months average higher (festival stretch). That is season. Seasonal naive uses last year’s same month.

Worked example C — Noise in hospital beds (Bengaluru).

Dataset note: fictional Surya Care daily beds occupied. 7 rows. Columns: day, beds_occupied.

import pandas as pd

hosp = pd.DataFrame({
    "day": pd.date_range("2026-10-20", periods=7, freq="D"),
    "beds_occupied": [142, 148, 151, 149, 155, 160, 158],
})
print(hosp)
print("Day-to-day change:", hosp["beds_occupied"].diff().tolist())

Output you should see.

         day  beds_occupied
0 2026-10-20            142
1 2026-10-21            148
2 2026-10-22            151
3 2026-10-23            149
4 2026-10-24            155
5 2026-10-25            160
6 2026-10-26            158
Day-to-day change: [nan, 6.0, 3.0, -2.0, 6.0, 5.0, -2.0]

What it means. Small up/down moves are often noise. Do not overfit them.

Ravindra Bagale's Tip

Look at the chart first. Trend? Season? Noise? Formula later. Your eyes are the first model.