0
0
Pandasdata~10 mins

Data aggregation reporting 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 calculate the average score from the DataFrame.

Pandas
average_score = df['score'].[1]()
Drag options to blanks, or click blank then click option'
Amean
Bsum
Ccount
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() instead of mean() will give the total, not the average.
Using count() returns the number of entries, not the average.
2fill in blank
medium

Complete the code to group the DataFrame by 'category' and calculate the sum of 'sales'.

Pandas
grouped = df.groupby('[1]')['sales'].sum()
Drag options to blanks, or click blank then click option'
Aregion
Bscore
Cdate
Dcategory
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by 'score' or 'date' will not group sales by category.
Using 'region' groups by location, not category.
3fill in blank
hard

Fix the error in the code to calculate the maximum value in the 'price' column.

Pandas
max_price = df['price'].[1]()
Drag options to blanks, or click blank then click option'
Amax
Bmaximum
Cmax_value
DmaxPrice
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'maximum' or 'max_value' causes errors because they are not pandas functions.
Using camelCase like 'maxPrice' is incorrect in pandas.
4fill in blank
hard

Fill both blanks to create a dictionary with 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)
Bword > 3
Clen(word) > 3
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word > 3' compares a string to a number, causing errors.
Using 'word' alone in the condition does not filter by length.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase keys and values greater than zero.

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 uppercase keys.
Using '<' instead of '>' in the condition.
Using keys or values incorrectly in the dictionary.