Challenge - 5 Problems
Rolling Std Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of rolling standard deviation with window=3
What is the output of the following code snippet?
Pandas
import pandas as pd s = pd.Series([1, 2, 3, 4, 5]) result = s.rolling(window=3).std() print(result.to_list())
Attempts:
2 left
💡 Hint
Remember pandas uses sample standard deviation by default (ddof=1).
✗ Incorrect
The rolling standard deviation with window=3 calculates the sample standard deviation (ddof=1) of each 3-element window. For the first two elements, there are not enough values, so the result is NaN. The standard deviation of [1,2,3] is approximately 0.8165 (sqrt(2/3)), and this repeats for subsequent windows.
❓ data_output
intermediate1:30remaining
Number of non-NaN values in rolling std result
Given a pandas Series of length 10, what is the number of non-NaN values in the result of rolling standard deviation with window=4?
Pandas
import pandas as pd s = pd.Series(range(10)) result = s.rolling(window=4).std() count_non_nan = result.count() print(count_non_nan)
Attempts:
2 left
💡 Hint
Rolling window of size 4 produces NaN for the first 3 elements.
✗ Incorrect
With window=4, the first 3 elements have insufficient data for std calculation, so they are NaN. The remaining 7 elements have valid std values, so count is 7.
🔧 Debug
advanced1:30remaining
Identify the error in rolling std calculation
What error does the following code raise?
Pandas
import pandas as pd s = pd.Series([1, 2, 3, 4, 5]) result = s.rolling(window=3).std(ddof=0) print(result)
Attempts:
2 left
💡 Hint
Check if ddof is a valid argument for pandas rolling std.
✗ Incorrect
The rolling std method accepts ddof parameter to specify degrees of freedom. ddof=0 calculates population standard deviation. No error occurs.
🚀 Application
advanced2:00remaining
Using rolling std to detect volatility spikes
You have a pandas Series of daily stock prices. Which code snippet correctly creates a boolean Series marking days where the 5-day rolling standard deviation exceeds 2.0?
Pandas
import pandas as pd prices = pd.Series([10, 12, 11, 13, 15, 14, 16, 18, 17, 19])
Attempts:
2 left
💡 Hint
Volatility is measured by standard deviation, not mean or variance threshold directly.
✗ Incorrect
Option D correctly computes the 5-day rolling standard deviation and checks where it exceeds 2.0, producing a boolean Series marking volatility spikes.
🧠 Conceptual
expert2:00remaining
Effect of min_periods on rolling std output length
If you apply rolling standard deviation with window=4 and min_periods=2 on a Series of length 6, how many non-NaN values will the result contain?
Pandas
import pandas as pd s = pd.Series([1, 2, 3, 4, 5, 6]) result = s.rolling(window=4, min_periods=2).std() print(result.count())
Attempts:
2 left
💡 Hint
min_periods=2 means at least 2 values are needed to compute std, even if window is 4.
✗ Incorrect
With min_periods=2, rolling std starts producing values from the 2nd element onward. For length 6, that means 5 non-NaN values.