0
0
Pandasdata~10 mins

Why advanced grouping matters 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 group the DataFrame by the 'Category' column.

Pandas
grouped = df.groupby([1])
Drag options to blanks, or click blank then click option'
Adf['Category']
BCategory
C['Category']
D'Category'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the column without quotes causes an error.
Passing the whole column data instead of the column name.
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'
Amean
Bmax
Ccount
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() instead of mean() gives total, not average.
Using count() returns counts, not averages.
3fill in blank
hard

Fix the error in the code to group by 'Category' and 'Subcategory'.

Pandas
grouped = df.groupby([1])
Drag options to blanks, or click blank then click option'
A['Category', 'Subcategory']
B'Category', 'Subcategory'
C'Category Subcategory'
Ddf[['Category', 'Subcategory']]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string with both column names combined.
Passing the DataFrame slice instead of column names.
4fill in blank
hard

Fill both blanks to create a dictionary with word lengths greater than 3.

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 the word itself as the value instead of its length.
Using '<' instead of '>' in the condition.
5fill in blank
hard

Fill all three blanks to create a filtered 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.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() instead of k.upper().
Using '<' instead of '>' in the condition.