0
0
Data Analysis Pythondata~10 mins

Window functions (expanding, ewm) 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 expanding sum of the 'sales' column.

Data Analysis Python
import pandas as pd

data = {'sales': [10, 20, 30, 40, 50]}
df = pd.DataFrame(data)
df['expanding_sum'] = df['sales'].[1]().sum()
print(df)
Drag options to blanks, or click blank then click option'
Arolling
Bewm
Cexpanding
Dcumsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using rolling() instead of expanding()
Using cumsum() which is similar but not a window function
Using ewm() which is for exponential weighted calculations
2fill in blank
medium

Complete the code to calculate the exponentially weighted mean with a span of 3.

Data Analysis Python
import pandas as pd

data = {'values': [1, 2, 3, 4, 5]}
df = pd.DataFrame(data)
df['ewm_mean'] = df['values'].[1](span=3).mean()
print(df)
Drag options to blanks, or click blank then click option'
Arolling
Bewm
Cexpanding
Dcumsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using rolling() which uses fixed window size
Using expanding() which uses all previous data equally
Using cumsum() which is a simple cumulative sum
3fill in blank
hard

Fix the error in the code to calculate the expanding mean of the 'temperature' column.

Data Analysis Python
import pandas as pd

data = {'temperature': [22, 21, 23, 24, 25]}
df = pd.DataFrame(data)
df['expanding_mean'] = df['temperature'].[1]().mean
print(df)
Drag options to blanks, or click blank then click option'
Aexpanding
Brolling
Cewm
Dcumsum
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses after mean
Using rolling() instead of expanding()
Using cumsum() which is not a window function
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Data Analysis Python
words = ['data', 'science', 'is', 'fun']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of len(word) for values
Using < instead of > in the condition
Not filtering words by length
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.

Data Analysis Python
data = {'a': 1, 'b': -2, 'c': 3}
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using k instead of k.upper() for keys
Filtering with < instead of >
Using k instead of v for values