0
0
Data Analysis Pythondata~10 mins

Rolling window calculations in Data Analysis Python - 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 mean with a window size of 3.

Data Analysis Python
import pandas as pd

data = pd.Series([1, 2, 3, 4, 5])
rolling_mean = data.[1](3).mean()
print(rolling_mean)
Drag options to blanks, or click blank then click option'
Arolling_window
Brolling_mean
Crolling
Dwindow
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rolling_mean' instead of 'rolling' causes an AttributeError.
Using 'window' or 'rolling_window' are not valid pandas methods.
2fill in blank
medium

Complete the code to calculate the rolling sum with a window size of 4.

Data Analysis Python
import pandas as pd

data = pd.Series([10, 20, 30, 40, 50])
rolling_sum = data.rolling([1]).sum()
print(rolling_sum)
Drag options to blanks, or click blank then click option'
A4
B3
C2
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a window size smaller or larger than 4 changes the result.
Passing the window size as a string instead of an integer.
3fill in blank
hard

Fix the error in the code to calculate the rolling median with a window size of 3.

Data Analysis Python
import pandas as pd

data = pd.Series([5, 3, 8, 7, 10])
rolling_median = data.rolling(3).[1]()
print(rolling_median)
Drag options to blanks, or click blank then click option'
Amedian
Bmean
Csum
Dmode
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mean' calculates the average, not the median.
Using 'sum' adds values instead of finding the median.
Using 'mode' is not supported directly on rolling objects.
4fill in blank
hard

Fill both blanks to create a rolling window of size 2 and calculate the maximum value in each window.

Data Analysis Python
import pandas as pd

data = pd.Series([4, 7, 1, 8, 5])
rolling_max = data.[1]([2]).max()
print(rolling_max)
Drag options to blanks, or click blank then click option'
Arolling
B3
C2
Dwindow
Attempts:
3 left
💡 Hint
Common Mistakes
Using window size 3 instead of 2 changes the output.
Using 'window' instead of 'rolling' causes an error.
5fill in blank
hard

Fill all three blanks to create a rolling window of size 3, calculate the minimum value, and assign it to a new variable.

Data Analysis Python
import pandas as pd

data = pd.Series([9, 2, 6, 3, 7])
rolling_min = data.[1]([2]).[3]()
print(rolling_min)
Drag options to blanks, or click blank then click option'
Arolling
B3
Cmin
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'max' instead of 'min' returns the maximum values.
Using wrong window size changes the results.