EthicsComputerCourses
Join training +91 90532 10052

What You Should Already Know

Time Series · Lesson 1 of 31 Intermediate 5 min read Updated

By the end of this short lesson you will know exactly which skills this course expects, and you will have tested yourself on each one. If a test feels hard, you will also know which lesson to revise first.

This is an intermediate to advanced course. It does not teach Python or pandas from zero. Instead it builds on them, the way a bowler builds on fitness training. Spend fifteen minutes here and the rest of the course will feel much smoother.

The four skills you need

SkillWhat you should be comfortable withWhere to revise
PythonFunctions, loops, lists, dictionaries, f-stringsPython Tutorial
NumPy and pandasArrays, Series, DataFrame, selecting rows, groupbyData Science with Python
StatisticsMean, standard deviation, correlation, a straight-line fitStatistics Tutorial
Machine learning basicsTraining data, test data, fit and predictMachine Learning Introduction

You do not need calculus. Every formula in this course is shown with small numbers first, then in code. You also do not need to install anything: every example runs in your browser.

Self-test 1: plain Python

Step 1. Read the code below before you run it. Try to guess the two lines it prints.

Step 2. Run it and compare with your guess.

PythonRun it yourself
def weekly_total(daily_sales):
    """Add up one week of sales in rupees."""
    total = 0
    for amount in daily_sales:
        total += amount
    return total

week = {"Mon": 4200, "Tue": 3900, "Wed": 4100, "Thu": 4500, "Fri": 5200, "Sat": 6800, "Sun": 7100}
total = weekly_total(week.values())
best_day = max(week, key=week.get)
print(f"Week total: Rs {total:,}")
print(f"Best day: {best_day} (Rs {week[best_day]:,})")
Output
Week total: Rs 35,800
Best day: Sun (Rs 7,100)

You should be able to explain every line. week.values() gives the seven amounts. max(week, key=week.get) finds the key with the biggest value. {total:,} adds the thousands comma. If key=week.get puzzles you, revise Functions and Dictionaries.

Self-test 2: NumPy and pandas

Time series work happens almost entirely in pandas. A Series is a column of values with labels, called the index. In this course the index will usually be dates.

Step 1. Run the code. It counts cups of chai sold at a stall in Pune for one week.

Step 2. Change the seed from 42 to 7 and run it again. The numbers change, but they stay the same every time you use seed 7.

PythonRun it yourself
import numpy as np
import pandas as pd

rng = np.random.default_rng(42)
days = pd.date_range("2025-06-01", periods=7, freq="D")
cups = pd.Series(rng.integers(150, 250, size=7), index=days, name="chai_cups")

print(cups)
print("Mean:", cups.mean().round(1), " Std:", cups.std().round(1))
print("Busiest day:", cups.idxmax().day_name())
Output
2025-06-01    158
2025-06-02    227
2025-06-03    215
2025-06-04    193
2025-06-05    193
2025-06-06    235
2025-06-07    158
Freq: D, Name: chai_cups, dtype: int64
Mean: 197.0  Std: 30.9
Busiest day: Friday

A random seed is a starting number for the random generator. Using a fixed seed means you and your friend get exactly the same "random" numbers. Every example in this course builds its data this way, so your output will match the page.

If np.random.default_rng, pd.Series or idxmax are new to you, work through NumPy Random Numbers and pandas Series first.

Self-test 3: basic statistics

Forecasting borrows ideas from statistics all the time. You should know what a correlation of 0.97 means, and what a fitted straight line is.

PythonRun it yourself
import numpy as np

rng = np.random.default_rng(0)
temperature = np.arange(25, 41)                       # 25 to 40 degrees
ice_creams = 12 * temperature - 200 + rng.normal(0, 15, size=temperature.size)

r = np.corrcoef(temperature, ice_creams)[0, 1]
slope, intercept = np.polyfit(temperature, ice_creams, 1)
print(f"Correlation: {r:.2f}")
sign = "-" if intercept < 0 else "+"
print(f"Line: ice_creams = {slope:.1f} x temperature {sign} {abs(intercept):.1f}")
Output
Correlation: 0.97
Line: ice_creams = 10.5 x temperature - 154.6

A correlation close to 1 means the two move up together almost in a straight line. The fitted line says each extra degree sells about 10 more ice creams. The true value used to make the data was 12, and the noise pulled the estimate a little. If this is unclear, read Correlation vs Causation and Simple Linear Regression.

How this course is different

Earlier courses mostly treated rows as independent: one student, one flat, one customer. A time series is different. Today's value depends on yesterday's. That single fact changes how you clean data, how you split it, and how you test a model. The next lesson explains why.

Key points

  • You need comfortable Python, pandas Series and DataFrame skills, and basic statistics.
  • A pandas Series has values and an index; in this course the index is usually dates.
  • A fixed random seed makes "random" example data identical on every run.
  • Time series rows are not independent, which changes cleaning, splitting and testing.
  • Revise the linked lessons first if any self-test felt hard.

Exercise

Extend Self-test 2. Build 14 days of chai sales starting on 1 June 2025 with seed 42 and the same range. Print the mean of the first seven days and the mean of the last seven days, each rounded to one decimal place.

Show solution
Python
import numpy as np
import pandas as pd

rng = np.random.default_rng(42)
days = pd.date_range("2025-06-01", periods=14, freq="D")
cups = pd.Series(rng.integers(150, 250, size=14), index=days)

print("Week 1 mean:", cups.iloc[:7].mean().round(1))
print("Week 2 mean:", cups.iloc[7:].mean().round(1))
Output
Week 1 mean: 197.0
Week 2 mean: 206.6

iloc[:7] takes the first seven positions and iloc[7:] takes the rest. The first week matches Self-test 2 because the generator draws the same first seven numbers.

Quick Quiz

1. Why do the examples in this course use np.random.default_rng(seed) with a fixed seed?

2. In a pandas Series of daily sales, what is the index?

3. What is the main way a time series differs from a table of students?

Learn Time Series with a mentor

Free lessons get you started. Our Data Science & Machine Learning training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call