0
0
Data Analysis Pythondata~10 mins

Why groupby summarizes data by category in Data Analysis Python - 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.

Data Analysis Python
grouped = df.groupby([1])
Drag options to blanks, or click blank then click option'
A'Category'
B'Date'
C'Value'
D'Amount'
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by a numeric column like 'Value' instead of 'Category'.
Using a column name that does not exist in the DataFrame.
2fill in blank
medium

Complete the code to calculate the sum of values for each category.

Data Analysis Python
summary = df.groupby('Category').[1]()
Drag options to blanks, or click blank then click option'
Amax
Bmean
Ccount
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean() which calculates average instead of sum.
Using count() which counts rows, not sums values.
3fill in blank
hard

Fix the error in the code to group by 'Category' and get the average value.

Data Analysis Python
result = df.[1]('Category').mean()
Drag options to blanks, or click blank then click option'
Agroup_by
Bgroup
Cgroupby
Daggregate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'group' or 'group_by' which are not pandas methods.
Using 'aggregate' without specifying grouping first.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

Data Analysis Python
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Checking if the word is greater than 3 instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values, including only items where value is positive.

Data Analysis Python
result = [1]: [2] for [3], v in data.items() if v > 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Dv.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using value as key or uppercase value instead of uppercase key.
Not iterating over key and value pairs correctly.