0
0
Pandasdata~10 mins

Split-apply-combine mental model in Pandas - Interactive Code Practice

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

Complete the code to group the DataFrame by the 'team' column.

Pandas
grouped = df.[1]('team')
Drag options to blanks, or click blank then click option'
Amerge
Bsort
Cfilter
Dgroupby
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sort' instead of 'groupby' will not create groups.
Using 'filter' or 'merge' does not split the data.
2fill in blank
medium

Complete the code to calculate the mean score for each group.

Pandas
mean_scores = grouped['score'].[1]()
Drag options to blanks, or click blank then click option'
Acount
Bsum
Cmean
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sum' adds values instead of averaging.
Using 'count' counts items, not values.
Using 'max' finds the largest value, not the average.
3fill in blank
hard

Fix the error in the code to apply a custom function to each group.

Pandas
result = grouped['score'].[1](lambda x: x.max() - x.min())
Drag options to blanks, or click blank then click option'
Aapply
Btransform
Caggregate
Dfilter
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'aggregate' expects named functions or dicts, not lambdas directly.
Using 'transform' returns a transformed version with the same shape.
Using 'filter' selects groups, not applies functions.
4fill in blank
hard

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

Pandas
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword.startswith('a')
Dword == 'data'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a condition unrelated to length will filter wrong words.
Using the word itself instead of its length for the value.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase keys and values filtered by positive values.

Pandas
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase keys instead of uppercase.
Using '<' instead of '>' causing wrong filtering.
Using keys as values or vice versa.