DA0-002 Data Acquisition and Preparation Practice Question
In pandas, you have a DataFrame 'df' with columns 'product' and 'sales'. You want to calculate the total sales per product. Which method should you use?
⚠ Common exam trap
Watch out — candidates often confuse element-wise operations (apply, map) with group-wise aggregation (groupby), leading candidates to pick apply(sum) thinking it aggregates when it actually operates per element.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
df.groupby('product')['sales'].sum()
The groupby('product')['sales'].sum() pattern is the canonical pandas idiom for split-apply-combine aggregation: it groups rows by the 'product' column, selects the 'sales' Series, and applies the sum aggregator to each group, returning a Series indexed by product. This is the most direct and efficient way to compute total sales per product.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
df['sales'].apply(sum)
Why it's wrong here
apply(sum) sums each element of the sales Series individually, returning the same values rather than totals per product. It is tempting because apply is the general mechanism for running functions across a Series or DataFrame. Aggregating sales per product requires groupby('product')['sales'].sum().
- ✗
df.pivot_table(values='sales', index='product', aggfunc='sum')
Why it's wrong here
Although `pivot_table` can aggregate data, it requires a unique index–column combination to reshape the table, whereas the question only needs a simple grouped sum without restructuring. It is tempting because `pivot_table` does accept `aggfunc='sum'`, making it appear suitable for aggregation; it would be correct if the goal were to reorganise the DataFrame into a cross-tabulation with multiple column categories, not merely to compute totals per product.
- ✓
df.groupby('product')['sales'].sum()
Why this is correct
groupby('product') partitions rows by category, then selecting ['sales'] and calling sum() aggregates each group into total sales per product. This satisfies the per-product aggregation requirement; pivot_table or value_counts would reshape or count rather than sum the sales column.
- ✗
df.merge(df, on='product')
Why it's wrong here
merge joins DataFrames on a key and returns matched rows, so merging df with itself duplicates rows rather than aggregating sales. It is tempting because merge is the tool for combining datasets, which is correct when relating separate tables. Grouping by product and summing sales requires groupby with sum.
About these practice questions
One of 1,004 original DA0-002 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official CompTIA exam blueprint
This DA0-002 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DA0-002 exam.