Complete the code to calculate the rolling average of sales over 3 days.
df['rolling_avg'] = df['sales'].[1](3).mean()
The rolling function creates a rolling window to calculate statistics like the mean over a fixed number of rows.
Complete the code to calculate the cumulative sum of sales.
df['cumulative_sales'] = df['sales'].[1]()
The cumsum function calculates the cumulative sum, adding each value to the sum of all previous values.
Fix the error in the code to calculate the expanding maximum of sales.
df['expanding_max'] = df['sales'].[1]().max()
The expanding function creates a window that expands from the start to the current row, useful for cumulative calculations like max.
Fill in the blank to calculate the difference between current sales and the previous day's sales.
df['sales_diff'] = df['sales'].[1]()
shift() moves the values but does not compute the difference.cumsum() computes cumulative sums, not differences.rolling requires a window size and computes statistics over windows.The diff() function calculates the difference between the current value and the previous row's value.
Fill all three blanks to create a dictionary of words and their lengths for words longer than 4 characters.
lengths = { [1]: [2] for [3] in words if len([3]) > 4 }This dictionary comprehension uses word as the variable, maps each word to its length using len(word), and iterates over word in the list words.