Challenge - 5 Problems
Exponential Moving Average Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of ewm() with span parameter
What is the output of the following code snippet?
Pandas
import pandas as pd s = pd.Series([10, 20, 30, 40, 50]) ewm_result = s.ewm(span=3, adjust=False).mean() print(ewm_result.round(2))
Attempts:
2 left
💡 Hint
Remember that adjust=False means the weights are calculated recursively without adjusting for prior weights.
✗ Incorrect
With span=3 and adjust=False, the ewm() calculates the exponential moving average giving more weight to recent values. The output is a series of smoothed values starting at the first value.
❓ data_output
intermediate1:30remaining
Number of items in ewm result with min_periods
How many non-NaN values are in the result of this code?
Pandas
import pandas as pd s = pd.Series([5, 10, 15, 20, 25]) ewm_result = s.ewm(span=2, min_periods=3).mean() print(ewm_result.dropna().count())
Attempts:
2 left
💡 Hint
min_periods sets the minimum number of observations required to have a value.
✗ Incorrect
Since min_periods=3, the first two values are NaN. From the third value onward, the ewm mean is calculated, so 3 values are non-NaN.
🔧 Debug
advanced1:30remaining
Identify the error in ewm() usage
What error does this code raise?
Pandas
import pandas as pd s = pd.Series([1, 2, 3, 4]) ewm_result = s.ewm(com=0, span=2).mean()
Attempts:
2 left
💡 Hint
Check the parameters passed to ewm().
✗ Incorrect
You cannot specify both 'com' and 'span' parameters together in ewm(). This raises a ValueError.
🚀 Application
advanced2:00remaining
Using ewm() to smooth noisy data
You have a noisy time series data. Which ewm() parameter setting will give the smoothest result?
Attempts:
2 left
💡 Hint
A larger span means more smoothing.
✗ Incorrect
A larger span (10) with adjust=True gives more weight to all past data, resulting in smoother output.
🧠 Conceptual
expert2:00remaining
Effect of adjust parameter in ewm()
Which statement best describes the effect of adjust=False in pandas ewm()?
Attempts:
2 left
💡 Hint
Think about how weights are applied when adjust=False.
✗ Incorrect
With adjust=False, the calculation uses recursive weights without normalizing over all past data, emphasizing recent points more.