Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() instead of mean()
Using count() which counts values, not averages
✗ Incorrect
The mean() function calculates the average value of the 'score' column.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using min() which finds the smallest value
Using mean() which calculates average
✗ Incorrect
The max() function returns the highest value in the 'age' column.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string with comma-separated functions
Passing a set instead of a list
✗ Incorrect
agg() expects a list of function names as strings to apply multiple aggregations.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by 'age' instead of 'gender'
Using sum and min instead of mean and max
✗ Incorrect
Group by 'gender' and aggregate 'height' with mean and max functions.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up aggregation functions for columns
Using count instead of sum for sales
✗ Incorrect
Use 'mean' for score, 'max' for age, and 'sum' for sales in the aggregation dictionary.