Coderhouse goes global

🌍

Read more

Time Series Analysis for Beginners: Trends, Seasonality, and Simple Forecasts

AI Engineering

Build and ship real applications with LLMs, agents and automation.

8 weeks · Live online · View course →

Data Analytics

Go from zero to job-ready analyst with SQL, Python and BI tools.

10 weeks · Live online · View course →

Dan Patiño

AI Strategy & Innovation at Coderhouse

Data

Time Series Analysis for Beginners: Trends, Seasonality, and Simple Forecasts

Time Series Analysis for Beginners: Trends, Seasonality, and Simple Forecasts

Time series analysis is the study of data points recorded in order over time, such as daily sales, weekly signups, or hourly website traffic, to understand how they change and to forecast what comes next. What makes time series different from other data is that order matters: today's value is usually related to yesterday's, and patterns repeat by week, month, or season. For data analysts, it is one of the most practical skills to have, because almost every business metric is reported over time and someone always asks, "what will next month look like?"

This beginner's guide explains the core components of a time series, a step-by-step workflow in Python, simple forecasting methods, and the mistakes that produce misleading forecasts.

The components of a time series

Most business time series can be described as a mix of a few parts. The free textbook Forecasting: Principles and Practice by Rob Hyndman and George Athanasopoulos explains them in detail:

  • Trend: the long-term direction, such as steady growth in active users.

  • Seasonality: patterns that repeat at a fixed period, such as higher sales every weekend or every December.

  • Cycles: rises and falls without a fixed period, often tied to the economy or business cycles.

  • Noise: random variation left over after the other parts are accounted for.

Separating these parts is called decomposition, and it is usually the first real analysis step: it tells you whether a recent jump is growth, a seasonal peak, or just noise.

Step-by-step time series analysis in Python

Step 1: Load the data with a proper date index

import pandas as pd
df = pd.read_csv("daily_sales.csv", parse_dates=["date"])
ts = df.set_index("date")["revenue"].asfreq("D")
ts.isna().sum()   # missing days after setting a daily frequency
import pandas as pd
df = pd.read_csv("daily_sales.csv", parse_dates=["date"])
ts = df.set_index("date")["revenue"].asfreq("D")
ts.isna().sum()   # missing days after setting a daily frequency
import pandas as pd
df = pd.read_csv("daily_sales.csv", parse_dates=["date"])
ts = df.set_index("date")["revenue"].asfreq("D")
ts.isna().sum()   # missing days after setting a daily frequency
import pandas as pd
df = pd.read_csv("daily_sales.csv", parse_dates=["date"])
ts = df.set_index("date")["revenue"].asfreq("D")
ts.isna().sum()   # missing days after setting a daily frequency

Setting an explicit frequency reveals gaps. A missing day might mean zero sales or a broken data load, and the right fix depends on which. The pandas time series guide covers resampling, frequencies, and date handling.

Step 2: Plot it before doing anything else

A simple line chart shows trend, obvious seasonality, outliers, and structural breaks, such as a pricing change, faster than any statistic. Line charts are the default for data over time; see how to choose the right chart for other cases. This is the time series version of exploratory data analysis.

Step 3: Smooth and resample

weekly = ts.resample("W").sum()
rolling = ts.rolling(window=7).mean()   # 7-day moving average
weekly = ts.resample("W").sum()
rolling = ts.rolling(window=7).mean()   # 7-day moving average
weekly = ts.resample("W").sum()
rolling = ts.rolling(window=7).mean()   # 7-day moving average
weekly = ts.resample("W").sum()
rolling = ts.rolling(window=7).mean()   # 7-day moving average

Daily data is noisy. A seven-day moving average removes the weekday pattern and makes the trend easier to see. Resampling to weeks or months is often enough for planning conversations.

Step 4: Decompose trend and seasonality

from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(ts.dropna(), model="additive", period=7)
result.plot()
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(ts.dropna(), model="additive", period=7)
result.plot()
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(ts.dropna(), model="additive", period=7)
result.plot()
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(ts.dropna(), model="additive", period=7)
result.plot()

Use an additive model when seasonal swings stay roughly the same size, and a multiplicative model when they grow with the level of the series. The statsmodels time series documentation lists this and more advanced tools.

Step 5: Check for unusual points

Promotions, outages, and holidays create spikes that can distort both decomposition and forecasts. Mark them, and decide whether to adjust, model, or exclude them. Our guide on how analysts detect and handle outliers covers the general approach.

Simple forecasting methods to start with

Before reaching for complex models, try baselines. They are easy to explain and surprisingly hard to beat on short horizons.

  • Naive forecast: next period equals the last observed value.

  • Seasonal naive: next Monday equals last Monday. Often strong for weekly retail or traffic data.

  • Moving average: next period equals the average of the last N periods.

  • Exponential smoothing: a weighted average that gives more weight to recent values; Holt-Winters versions also handle trend and seasonality.

  • ARIMA-type models: statistical models that use past values and past errors; useful once you understand the basics.

from statsmodels.tsa.holtwinters import ExponentialSmoothing
train, test = weekly[:-8], weekly[-8:]
model = ExponentialSmoothing(train, trend="add", seasonal=None).fit()
forecast = model.forecast(8)
mae = (forecast - test).abs().mean()
from statsmodels.tsa.holtwinters import ExponentialSmoothing
train, test = weekly[:-8], weekly[-8:]
model = ExponentialSmoothing(train, trend="add", seasonal=None).fit()
forecast = model.forecast(8)
mae = (forecast - test).abs().mean()
from statsmodels.tsa.holtwinters import ExponentialSmoothing
train, test = weekly[:-8], weekly[-8:]
model = ExponentialSmoothing(train, trend="add", seasonal=None).fit()
forecast = model.forecast(8)
mae = (forecast - test).abs().mean()
from statsmodels.tsa.holtwinters import ExponentialSmoothing
train, test = weekly[:-8], weekly[-8:]
model = ExponentialSmoothing(train, trend="add", seasonal=None).fit()
forecast = model.forecast(8)
mae = (forecast - test).abs().mean()

How to evaluate a forecast

Never shuffle time series data into random train and test sets. Always train on the past and test on a later period, as in the example above, so the evaluation mimics real use. Compare models with error measures such as mean absolute error (MAE) and always include a naive baseline. If a sophisticated model does not beat the seasonal naive forecast, use the simpler one.

Report forecasts as ranges, not single numbers. A forecast of "between 900 and 1,100 orders next week" is more honest and more useful for planning than "1,000 orders."

Common beginner mistakes

  • Ignoring the calendar. Different numbers of weekdays, holidays, and month lengths change totals. Compare like with like.

  • Extrapolating a short trend. A few weeks of growth after a launch rarely continues in a straight line.

  • Using future information. Features that would not be known at forecast time, such as final monthly totals, make test results look better than reality.

  • Confusing correlation with cause. Two series that both trend upward will look correlated even if unrelated. Look at changes, not just levels.

  • Forgetting structural breaks. A pricing change or new tracking setup can make older data a poor guide to the future.

Frequently asked questions

Do I need machine learning for time series forecasting?

Not to start. Baselines and exponential smoothing handle many business cases well. Machine learning models help when you have many related series or useful external variables.

How much history do I need?

At least a few full seasonal cycles if you want to model seasonality. For yearly seasonality, that usually means two or more years of data.

Can I do time series analysis in Excel or SQL?

Yes, for the basics. Moving averages, period-over-period comparisons, and simple trend lines work in both. Python becomes more useful for decomposition, model comparison, and repeatable workflows. If your foundations need a refresh first, see statistics for data analysts.

Practice with real business data

If you want to analyze real datasets with live guidance and feedback, Coderhouse offers online courses with one live class per week:

  • Data Analytics Course: 11 weeks for career switchers, analysts, and data-driven professionals, covering business framing, SQL, Python, experimentation, visualization, and AI-assisted analytics.

  • AI Engineering Course: 8 weeks for experienced developers moving into AI engineering, covering LLM applications, retrieval, agents, evaluation, and deployment.

Dan Patiño

I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.