0
0
Pandasdata~10 mins

Multiple aggregation functions 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 mean of the 'score' column using pandas.

Pandas
mean_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()
Using count() which counts values, not averages
2fill in blank
medium

Complete the code to calculate the maximum value of the 'age' column.

Pandas
max_age = df['age'].[1]()
Drag options to blanks, or click blank then click option'
Amedian
Bmax
Cmean
Dmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using min() which finds the smallest value
Using mean() which calculates average
3fill in blank
hard

Fix the error in the code to calculate both mean and sum of the 'sales' column using agg.

Pandas
result = df['sales'].agg([1])
Drag options to blanks, or click blank then click option'
A{'mean', 'sum'}
B'mean, sum'
Cmean, sum
D['mean', 'sum']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string with comma-separated functions
Passing a set instead of a list
4fill in blank
hard

Fill both blanks to calculate mean and max of 'height' grouped by 'gender'.

Pandas
grouped = df.groupby('[1]')['height'].agg([2])
Drag options to blanks, or click blank then click option'
Agender
Bage
C['mean', 'max']
D['sum', 'min']
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by 'age' instead of 'gender'
Using sum and min instead of mean and max
5fill in blank
hard

Fill all three blanks to create a dictionary for aggregation: mean of 'score', max of 'age', and sum of 'sales'.

Pandas
agg_dict = {'score': [1], 'age': [2], 'sales': [3]
Drag options to blanks, or click blank then click option'
A'mean'
B'max'
C'sum'
D'count'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up aggregation functions for columns
Using count instead of sum for sales