0
0
Pandasdata~10 mins

Why window functions matter in Pandas - Test Your Understanding

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

Complete the code to calculate the rolling average of sales over 3 days.

Pandas
df['rolling_avg'] = df['sales'].[1](3).mean()
Drag options to blanks, or click blank then click option'
Arolling
Bgroupby
Csort_values
Dcumsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using groupby instead of rolling will group data but not create a moving window.
Using cumsum adds values cumulatively but does not average over a window.
2fill in blank
medium

Complete the code to calculate the cumulative sum of sales.

Pandas
df['cumulative_sales'] = df['sales'].[1]()
Drag options to blanks, or click blank then click option'
Arolling
Bcumsum
Cmean
Dshift
Attempts:
3 left
💡 Hint
Common Mistakes
Using rolling.mean() calculates a moving average, not a cumulative sum.
Using shift() moves data but does not sum values.
3fill in blank
hard

Fix the error in the code to calculate the expanding maximum of sales.

Pandas
df['expanding_max'] = df['sales'].[1]().max()
Drag options to blanks, or click blank then click option'
Arolling
Bgroupby
Cexpanding
Dcumsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using rolling().max() calculates a fixed window max, not expanding.
Using groupby() groups data but does not create expanding windows.
4fill in blank
hard

Fill in the blank to calculate the difference between current sales and the previous day's sales.

Pandas
df['sales_diff'] = df['sales'].[1]()
Drag options to blanks, or click blank then click option'
Adiff
Bcumsum
Cshift
Drolling
Attempts:
3 left
💡 Hint
Common Mistakes
Using shift() moves the values but does not compute the difference.
Using cumsum() computes cumulative sums, not differences.
Using rolling requires a window size and computes statistics over windows.
5fill in blank
hard

Fill all three blanks to create a dictionary of words and their lengths for words longer than 4 characters.

Pandas
lengths = { [1]: [2] for [3] in words if len([3]) > 4 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently causes errors.
Using len(word) as a key instead of value reverses the dictionary.