0
0
Data Analysis Pythondata~5 mins

Window functions (expanding, ewm) in Data Analysis Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an expanding window function in data analysis?
An expanding window function calculates a statistic over all data points from the start up to the current point, growing the window as it moves forward.
Click to reveal answer
intermediate
Explain the difference between an expanding window and a rolling window.
An expanding window grows from the start to the current point, including all previous data, while a rolling window uses a fixed-size window that moves along the data.
Click to reveal answer
beginner
What does the ewm (exponentially weighted moving) function do?
The ewm function calculates statistics giving more weight to recent data points, making the result more sensitive to recent changes.
Click to reveal answer
intermediate
How does the 'span' parameter affect the ewm function?
The 'span' controls how quickly the weights decrease for older data; a smaller span means more weight on recent points, while a larger span smooths more over time.
Click to reveal answer
beginner
Show a simple Python example using pandas to calculate an expanding mean.
import pandas as pd
s = pd.Series([1, 2, 3, 4, 5])
expanding_mean = s.expanding().mean()
print(expanding_mean)

This prints the mean of all values from the start up to each point.
Click to reveal answer
What does the expanding() function in pandas do?
ACalculates statistics over all data from the start to current point
BCalculates statistics over a fixed-size window
CCalculates statistics giving more weight to recent data
DCalculates statistics only on the last data point
Which window function gives more importance to recent data points?
Aexpanding()
Brolling()
Ccumsum()
Dewm()
In ewm(span=5), what does the span control?
AThe total number of data points used
BThe size of the fixed window
CHow fast weights decrease for older data
DThe minimum number of observations
Which pandas function would you use to calculate a rolling average over the last 3 data points?
Arolling(window=3)
Bewm(span=3)
Cexpanding()
Dcumsum()
What will s.expanding().mean() return for s = pd.Series([2, 4, 6])?
A[2, 4, 6]
B[2, 3, 4]
C[2, 3, 5]
D[2, 4, 5]
Describe how expanding window functions work and give a real-life example where they might be useful.
Think about tracking a running average that includes all past data.
You got /3 concepts.
    Explain the purpose of the ewm function and how changing its parameters affects the result.
    Consider how recent events might be more important in stock prices.
    You got /3 concepts.