0
0
Pandasdata~10 mins

Rolling standard deviation in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the rolling standard deviation with a window size of 3.

Pandas
import pandas as pd

data = pd.Series([1, 2, 3, 4, 5])
rolling_std = data.[1](3).std()
print(rolling_std)
Drag options to blanks, or click blank then click option'
Arolling
Bmean
Csum
Dcumsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean() instead of rolling().
Trying to call std() directly on the Series without rolling.
2fill in blank
medium

Complete the code to calculate the rolling standard deviation with a window size of 4 and minimum periods of 2.

Pandas
import pandas as pd

data = pd.Series([10, 20, 30, 40, 50])
rolling_std = data.rolling(window=[1], min_periods=2).std()
print(rolling_std)
Drag options to blanks, or click blank then click option'
A2
B4
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong window size like 2 or 3.
Confusing min_periods with window.
3fill in blank
hard

Fix the error in the code to correctly calculate the rolling standard deviation with a window size of 3.

Pandas
import pandas as pd

data = pd.Series([5, 10, 15, 20, 25])
rolling_std = data.rolling(3).[1]()
print(rolling_std)
Drag options to blanks, or click blank then click option'
Asum
Bmean
Cvar
Dstd
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean() instead of std().
Using var() which calculates variance, not standard deviation.
4fill in blank
hard

Fill both blanks to create a dictionary of words and their rolling standard deviation of lengths with window size 2, filtering lengths greater than 3.

Pandas
import pandas as pd

words = ['apple', 'bat', 'cat', 'dog', 'elephant']
lengths = {word: len(word) for word in words}
rolling_std = pd.Series(list(lengths.values())).rolling([1]).std()
filtered = {word: rolling_std[i] for i, word in enumerate(words) if lengths[word] [2] 3}
print(filtered)
Drag options to blanks, or click blank then click option'
A2
B>
C<
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong window size like 3 or 4.
Using '<' instead of '>' in the filter condition.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their rolling standard deviation of lengths with window size 2, filtering lengths less than or equal to 5.

Pandas
import pandas as pd

words = ['apple', 'bat', 'cat', 'dog', 'elephant']
lengths = {word: len(word) for word in words}
rolling_std = pd.Series(list(lengths.values())).rolling([1]).std()
filtered = {word.[2](): rolling_std[i] for i, word in enumerate(words) if lengths[word] [3] 5}
print(filtered)
Drag options to blanks, or click blank then click option'
A2
Bupper
C<=
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong window size like 3.
Using lower() instead of upper().
Using '<' or '>' instead of '<=' in the filter.