Recall & Review
beginner
What is a rolling mean in pandas?
A rolling mean calculates the average of values in a moving window over a series. It helps smooth out short-term fluctuations and highlight longer-term trends.
Click to reveal answer
beginner
How do you calculate a rolling sum in pandas?
Use the
rolling(window).sum() method on a pandas Series or DataFrame to get the sum of values within a moving window of specified size.Click to reveal answer
beginner
What does the
window parameter specify in rolling calculations?The
window parameter sets the size of the moving window, i.e., how many consecutive values are included in each calculation.Click to reveal answer
intermediate
What happens to the first few values when using rolling mean with a window size of 3?
The first two values will be
NaN because there are not enough data points to fill the window of size 3.Click to reveal answer
intermediate
How can you include the current row in the rolling window calculation?
By default, the rolling window includes the current row and previous rows up to the window size. You can adjust this with parameters like
min_periods or center.Click to reveal answer
Which pandas method calculates the rolling mean?
✗ Incorrect
The method
rolling(window).mean() computes the rolling mean over the specified window.If you use
rolling(4).sum() on a Series, what does the number 4 represent?✗ Incorrect
The number 4 is the window size, meaning the sum is calculated over 4 consecutive values.
What will be the output for the first value when using
rolling(3).mean()?✗ Incorrect
The first value is NaN because there are not enough values to fill the window of size 3.
How can you change the rolling window to be centered on the current row?
✗ Incorrect
Setting
center=True centers the window on the current row.What does
min_periods control in rolling calculations?✗ Incorrect
min_periods sets the minimum number of data points required in the window to compute a result instead of returning NaN.Explain how rolling mean and rolling sum work in pandas and why they are useful.
Think about how you might smooth noisy data or find running totals.
You got /4 concepts.
Describe how to use the
rolling() method with parameters to customize the window behavior.Consider how to adjust window size and alignment.
You got /4 concepts.