Skip to content
Learn Netverks

Lesson

Step 26/36 72% through track

rolling-windows

Rolling windows

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Rolling windows: Pandas tabular manipulation—indexing, dtypes, reshaping, and analysis habits for real-world tables.

Teams apply Rolling windows in every serious Pandas project—skipping it leaves blind spots in analysis and reviews.

You will apply Rolling windows in contexts like: CSV/Parquet analysis, ETL notebooks, and ad hoc reporting.

Read the narrative, run `import pandas as pd` snippets with in-memory DataFrames (install pandas and numpy with pip if needed), inspect `.head()`, `.dtypes`, and complete MCQs.

When you can explain the previous lesson's ideas in your own words.

rolling(n) computes moving statistics over a fixed window; expanding() grows from the start; ewm() applies exponential decay weights—common for trends and smoothing.

rolling mean

import pandas as pd
import numpy as np

s = pd.Series([1, 2, 3, 4, 5])
print(s.rolling(3).mean())

Parameters

  • window — number of observations (or time offset for time-based)
  • min_periods — minimum obs before value (default = window)
  • center=True — center window on each point

DataFrame rolling

df = pd.DataFrame({'a': [1,2,3,4,5], 'b': [5,4,3,2,1]})
print(df.rolling(2).sum())

Important interview questions and answers

  1. Q: rolling vs shift?
    A: rolling aggregates over window; shift moves values by periods (lag features).
  2. Q: NaN at start?
    A: First window-1 rows often NaN until min_periods satisfied.

Self-check

  1. Compute 3-period rolling mean.
  2. What does min_periods=1 change?

Tip: Pair rolling with datetime index for time-based windows like '7D'.

Interview prep

rolling vs expanding?

rolling fixed window; expanding grows from start.

min_periods?

Allow partial windows at series start.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • rolling vs expanding?
  • min_periods?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump