0
0
Pandasdata~10 mins

Why grouping data 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.[1]('Category')
Drag options to blanks, or click blank then click option'
Asort
Bfilter
Cgroupby
Dmerge
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sort' instead of 'groupby' will only sort data, not group it.
Using 'filter' or 'merge' does not create groups.
2fill in blank
medium

Complete the code to calculate the average sales for each group.

Pandas
average_sales = grouped.[1]()['Sales']
Drag options to blanks, or click blank then click option'
Amean
Bsum
Ccount
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sum' will add values instead of averaging.
Using 'count' returns the number of items, not the average.
3fill in blank
hard

Fix the error in the code to get the total sales per group.

Pandas
total_sales = df.groupby('Category').[1]()
Drag options to blanks, or click blank then click option'
Acount
Baverage
Cmean
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'average' is not a valid pandas method.
Using 'mean' calculates average, not total.
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 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 '<' will select words shorter than 3 characters.
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 of uppercase words and their counts for words with count greater than 1.

Pandas
result = [1]: [2] for word, count in word_counts.items() if count [3] 1
Drag options to blanks, or click blank then click option'
Aword.upper()
Bcount
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word' instead of 'word.upper()' will not change case.
Using '<' will filter counts less than or equal to 1.