Bird
Raised Fist0
Data Analysis Pythondata~20 mins

Aggregation functions (sum, mean, std) in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Aggregation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of sum aggregation on DataFrame column
What is the output of the following code snippet?
Data Analysis Python
import pandas as pd

df = pd.DataFrame({'values': [10, 20, 30, 40]})
result = df['values'].sum()
print(result)
A40
BTypeError
C100
D25
Attempts:
2 left
💡 Hint
Sum adds all numbers in the column.
❓ data_output
intermediate
2:00remaining
Mean value of grouped data
Given the DataFrame below, what is the mean value of group 'B'?
Data Analysis Python
import pandas as pd

df = pd.DataFrame({'group': ['A', 'B', 'B', 'A', 'B'], 'score': [5, 10, 15, 20, 25]})
mean_b = df.groupby('group')['score'].mean().loc['B']
print(mean_b)
A16.666666666666668
B15
C10
D20
Attempts:
2 left
💡 Hint
Mean is the sum divided by count for group 'B'.
❓ Predict Output
advanced
2:00remaining
Standard deviation calculation on a list
What is the output of this code?
Data Analysis Python
import numpy as np

values = [2, 4, 4, 4, 5, 5, 7, 9]
std_dev = np.std(values, ddof=1)
print(round(std_dev, 2))
A2.14
B2.00
C2.31
D1.96
Attempts:
2 left
💡 Hint
ddof=1 means sample standard deviation.
❓ visualization
advanced
2:00remaining
Interpreting aggregation results in a bar chart
You have this code that plots mean scores by category. What does the bar height for category 'X' represent?
Data Analysis Python
import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({'category': ['X', 'Y', 'X', 'Y', 'X'], 'score': [3, 7, 5, 9, 4]})
mean_scores = df.groupby('category')['score'].mean()
mean_scores.plot(kind='bar')
plt.show()
AThe total sum of scores in category 'X'
BThe count of entries in category 'X'
CThe highest score recorded in category 'X'
DThe average score of all entries in category 'X'
Attempts:
2 left
💡 Hint
The code uses mean aggregation.
🧠 Conceptual
expert
2:00remaining
Understanding difference between population and sample std deviation
Which statement correctly explains the difference between population and sample standard deviation calculations?
APopulation std deviation divides by (n-1), sample divides by n
BSample std deviation divides by (n-1) to correct bias, population divides by n
CBoth divide by n but sample uses a different formula for variance
DSample std deviation always gives smaller values than population std deviation
Attempts:
2 left
💡 Hint
Think about degrees of freedom in statistics.

Practice

(1/5)
1. What does the mean() function calculate in a dataset?
easy
A. The most frequent value in the data
B. The total sum of all data points
C. The difference between the largest and smallest values
D. The average value of the data

Solution

  1. Step 1: Understand the purpose of mean()

    The mean() function calculates the average by adding all values and dividing by the count.
  2. Step 2: Compare with other options

    Sum is total, range is difference, mode is most frequent. Only mean is average.
  3. Final Answer:

    The average value of the data -> Option D
  4. Quick Check:

    mean = average [OK]
Hint: Mean is average, sum is total, std is spread [OK]
Common Mistakes:
  • Confusing mean with sum
  • Thinking mean finds the most frequent value
  • Mixing mean with range or mode
2. Which of the following is the correct way to calculate the standard deviation of a pandas DataFrame column named data?
easy
A. df.std(data)
B. std(df['data'])
C. df.data.std()
D. df['data'].standard_deviation()

Solution

  1. Step 1: Recall pandas syntax for std()

    In pandas, to get std of a column, use df.column.std() or df['column'].std().
  2. Step 2: Check each option

    df.data.std() uses correct dot notation. df.std(data) is wrong syntax. std(df['data']) is not a pandas function call. df['data'].standard_deviation() uses a non-existent method.
  3. Final Answer:

    df.data.std() -> Option C
  4. Quick Check:

    Use dot notation with std() [OK]
Hint: Use df.column.std() to get standard deviation [OK]
Common Mistakes:
  • Calling std() as a standalone function
  • Using wrong method names
  • Passing column name as argument to std()
3. Given the following code:
import pandas as pd
df = pd.DataFrame({'values': [10, 20, 30, 40, 50]})
result = df['values'].sum()

What is the value of result?
medium
A. 150
B. 30
C. 25
D. 10

Solution

  1. Step 1: Identify the data values

    The column 'values' contains [10, 20, 30, 40, 50].
  2. Step 2: Calculate the sum

    Sum = 10 + 20 + 30 + 40 + 50 = 150.
  3. Final Answer:

    150 -> Option A
  4. Quick Check:

    Sum of values = 150 [OK]
Hint: Add all numbers to get sum [OK]
Common Mistakes:
  • Calculating mean instead of sum
  • Adding only first two numbers
  • Confusing sum with count
4. The following code is intended to calculate the mean of a list but causes an error:
import pandas as pd
numbers = [5, 10, 15]
mean_value = numbers.mean()

What is the error and how to fix it?
medium
A. Error: 'list' object has no attribute 'mean'. Fix by converting list to pandas Series first.
B. Error: mean() requires two arguments. Fix by adding an argument.
C. Error: mean() is not imported. Fix by importing mean from pandas.
D. No error, code runs correctly.

Solution

  1. Step 1: Identify the error cause

    Python lists do not have a mean() method, so calling numbers.mean() causes an AttributeError.
  2. Step 2: Fix by converting list to pandas Series

    Convert list to pd.Series(numbers) then call .mean() to get the average.
  3. Final Answer:

    Error: 'list' object has no attribute 'mean'. Fix by converting list to pandas Series first. -> Option A
  4. Quick Check:

    Lists lack mean(), use pd.Series [OK]
Hint: Convert list to Series before calling mean() [OK]
Common Mistakes:
  • Calling mean() directly on list
  • Trying to import mean() separately
  • Assuming mean() needs arguments
5. You have a DataFrame df with a column scores containing exam scores. You want to find the average score but only for scores above 50. Which code correctly calculates this?
hard
A. df['scores'].mean(df['scores'] > 50)
B. df[df['scores'] > 50]['scores'].mean()
C. df['scores'].sum() / 50
D. df['scores'].std()[df['scores'] > 50]

Solution

  1. Step 1: Filter scores greater than 50

    Use df[df['scores'] > 50] to select rows where scores are above 50.
  2. Step 2: Calculate mean of filtered scores

    Access the 'scores' column of filtered data and call .mean() to get average.
  3. Final Answer:

    df[df['scores'] > 50]['scores'].mean() -> Option B
  4. Quick Check:

    Filter then mean = correct approach [OK]
Hint: Filter first, then apply mean() [OK]
Common Mistakes:
  • Passing condition inside mean()
  • Dividing sum by 50 instead of count
  • Using std() instead of mean()
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard