0
0
Data Analysis Pythondata~20 mins

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

Choose your learning style9 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 Python code using pandas?
Data Analysis Python
import pandas as pd

df = pd.DataFrame({'values': [10, 20, 30, 40]})
result = df['values'].sum()
print(result)
A40
BTypeError
C25
D100
Attempts:
2 left
💡 Hint

Sum adds all numbers in the column.

data_output
intermediate
2:00remaining
Count of non-null entries in DataFrame column
Given this DataFrame, what is the output of the count aggregation?
Data Analysis Python
import pandas as pd

df = pd.DataFrame({'scores': [5, None, 7, None, 9]})
result = df['scores'].count()
print(result)
A5
B3
C2
DNone
Attempts:
2 left
💡 Hint

Count counts only non-null values.

Predict Output
advanced
2:00remaining
Mean aggregation with missing values
What is the output of this code calculating the mean?
Data Analysis Python
import pandas as pd

df = pd.DataFrame({'temps': [20, 25, None, 30]})
result = df['temps'].mean()
print(round(result, 2))
ANone
B18.75
C25.0
DTypeError
Attempts:
2 left
💡 Hint

Mean ignores missing values by default.

visualization
advanced
3:00remaining
Bar chart of sum aggregation by group
Which option shows the correct bar chart output for sum of sales by region?
Data Analysis Python
import pandas as pd
import matplotlib.pyplot as plt

data = {'region': ['East', 'West', 'East', 'West'], 'sales': [100, 200, 150, 300]}
df = pd.DataFrame(data)
sum_sales = df.groupby('region')['sales'].sum()
sum_sales.plot(kind='bar')
plt.show()
ABar chart with East=250 and West=500
BBar chart with East=100 and West=200
CBar chart with East=150 and West=300
DLine chart with East=250 and West=500
Attempts:
2 left
💡 Hint

Group sums add sales per region.

🧠 Conceptual
expert
3:00remaining
Understanding count vs size in groupby
In pandas, what is the difference between using count() and size() after a groupby operation?
A<code>count()</code> counts non-null values per group; <code>size()</code> counts all rows per group including nulls.
B<code>count()</code> counts all rows including nulls; <code>size()</code> counts only non-null values.
C<code>count()</code> returns the sum of values; <code>size()</code> returns the mean.
D<code>count()</code> and <code>size()</code> are identical and interchangeable.
Attempts:
2 left
💡 Hint

Think about how missing data affects counts.