0
0
Pandasdata~10 mins

groupby() basics 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 'Category' column.

Pandas
grouped = df.[1]('Category')
Drag options to blanks, or click blank then click option'
Agroupby
Bsort
Cfilter
Dmerge
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sort' instead of 'groupby' will not group the data.
Using 'filter' or 'merge' are unrelated to grouping.
2fill in blank
medium

Complete the code to calculate the mean of each group.

Pandas
mean_values = df.groupby('Category').[1]()
Drag options to blanks, or click blank then click option'
Asum
Bcount
Cmean
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sum' adds values instead of averaging.
Using 'count' counts rows, not values.
Using 'max' finds the largest value, not the average.
3fill in blank
hard

Fix the error in the code to get the size of each group.

Pandas
group_sizes = df.groupby('Category').[1]
Drag options to blanks, or click blank then click option'
Asize()
Bsize
Ccount()
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses causes the variable to hold a method, not data.
Using 'count' counts non-null values per column, not total rows.
4fill in blank
hard

Fill both blanks to create a dictionary with word lengths for words longer than 3 letters.

Pandas
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will select shorter words.
Using 'word' instead of 'len(word)' will store the word itself, not its length.
5fill in blank
hard

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

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
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k' instead of 'k.upper()' keeps keys lowercase.
Using '<' instead of '>' selects values less than zero.
Using 'k' or 'v' incorrectly in the key or value positions.