Complete the code to calculate the rolling mean with a window size of 3.
import pandas as pd data = pd.Series([1, 2, 3, 4, 5]) rolling_mean = data.[1](3).mean() print(rolling_mean.tolist())
The rolling() function creates a moving window of the specified size (3 here). Then mean() calculates the average within each window.
Complete the code to calculate the rolling sum with a window size of 4.
import pandas as pd values = pd.Series([10, 20, 30, 40, 50]) rolling_sum = values.[1](4).sum() print(rolling_sum.tolist())
The rolling() function with window 4 creates windows of 4 elements. Then sum() adds values in each window.
Fix the error in the code to calculate the rolling max with a window size of 2.
import pandas as pd scores = pd.Series([5, 3, 8, 7]) rolling_max = scores.[1](window=2).max() print(rolling_max.tolist())
The correct pandas function is rolling(). Other options are invalid and cause errors.
Fill both blanks to create a rolling window of size 3 and calculate the rolling standard deviation.
import pandas as pd values = pd.Series([2, 4, 6, 8, 10]) rolling_std = values.[1]([2]).std() print(rolling_std.tolist())
rolling(3) creates a moving window of size 3. Then std() calculates the standard deviation in each window.
Fill all three blanks to create a rolling window of size 2, calculate the rolling median, and assign it to a new column in a DataFrame.
import pandas as pd data = pd.DataFrame({'values': [1, 3, 5, 7, 9]}) data['rolling_median'] = data['values'].[1]([2]).[3]() print(data)
rolling(2) creates windows of size 2, and median() calculates the median in each window. The result is assigned to a new column.