0
0
Pandasdata~20 mins

ewm() for exponential moving average in Pandas - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Exponential Moving Average Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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))
A[10.00, 15.00, 22.50, 31.25, 40.62]
B[10.00, 13.33, 19.44, 27.78, 37.96]
C[10.00, 20.00, 30.00, 40.00, 50.00]
D[10.00, 16.67, 25.56, 35.37, 45.91]
Attempts:
2 left
💡 Hint
Remember that adjust=False means the weights are calculated recursively without adjusting for prior weights.
data_output
intermediate
1: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())
A3
B2
C5
D0
Attempts:
2 left
💡 Hint
min_periods sets the minimum number of observations required to have a value.
🔧 Debug
advanced
1: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()
ANo error, runs successfully
BTypeError: ewm() got multiple values for argument 'span'
CValueError: com and span cannot be specified at the same time
DAttributeError: 'Series' object has no attribute 'ewm'
Attempts:
2 left
💡 Hint
Check the parameters passed to ewm().
🚀 Application
advanced
2:00remaining
Using ewm() to smooth noisy data
You have a noisy time series data. Which ewm() parameter setting will give the smoothest result?
Ahalflife=1, adjust=True
Bspan=10, adjust=True
Cspan=2, adjust=False
Dcom=0.5, adjust=False
Attempts:
2 left
💡 Hint
A larger span means more smoothing.
🧠 Conceptual
expert
2:00remaining
Effect of adjust parameter in ewm()
Which statement best describes the effect of adjust=False in pandas ewm()?
AWeights are normalized so the sum equals 1, considering all past data.
BThe ewm() function raises an error if adjust=False is used.
CThe result is a simple moving average ignoring weights.
DWeights are calculated recursively without normalization, giving more weight to recent data.
Attempts:
2 left
💡 Hint
Think about how weights are applied when adjust=False.