Courseiva

DA0-002 Data Acquisition and Preparation Practice Question

An analyst wants to use Python (pandas) to compute the average sales amount per region from a DataFrame 'df' with columns 'region' and 'sales'. Which TWO pandas operations are needed? (Select TWO).

⚠ Common exam trap

The trap is overcomplicating the question — candidates may look for a merge or a fillna step, but the core operation is simply group-and-aggregate, which both groupby().mean() and pivot_table() accomplish.

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.pivot_table(index='region', values='sales', aggfunc='mean')

Option B, df.pivot_table(index='region', values='sales', aggfunc='mean'), is correct because pivot_table with index='region' groups rows by region, selects the 'sales' column via values='sales', and applies the mean aggregation through aggfunc='mean', directly producing the average sales per region. Option E, df.groupby('region')['sales'].mean(), is correct because groupby('region') splits the DataFrame by region, ['sales'] selects the sales column, and .mean() computes the arithmetic average of sales within each group, yielding the same per-region averages. The other options do not compute grouped averages: A (df.fillna(0)) only replaces missing values with zero, C (df['sales'].apply(np.sqrt)) applies a square-root transformation element-wise, and D (df.merge(df2, on='region')) joins two DataFrames on the region key without any aggregation.

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.fillna(0)

    Why it's wrong here

    fillna(0) replaces missing values with zero, which alters the sales figures and skews the computed averages. It belongs in data cleaning when nulls must be imputed before analysis, not in a groupby-and-mean aggregation of existing values.

  • ✓

    df.pivot_table(index='region', values='sales', aggfunc='mean')

    Why this is correct

    `pivot_table` groups rows by the `region` column and applies `aggfunc='mean'` to the `sales` values, producing one averaged figure per region. This directly satisfies the stem's requirement to compute average sales amount per region, collapsing many rows into a single aggregated result keyed by region.

  • ✗

    df['sales'].apply(np.sqrt)

    Why it's wrong here

    Applying a square-root transform to the sales column changes each value rather than aggregating it, so no per-region average is produced. It is tempting because `apply` genuinely maps a function element-wise, which suits feature scaling or distribution reshaping, but grouping by region and computing a mean requires `groupby` with `mean`.

  • ✗

    df.merge(df2, on='region')

    Why it's wrong here

    merge joins two DataFrames on a shared column, but the average per region needs no second DataFrame. It is correct when combining separate tables, such as attaching region metadata, not when aggregating one frame's sales column.

  • ✓

    df.groupby('region')['sales'].mean()

    Why this is correct

    Grouping by 'region' partitions rows into regional subsets, then selecting the 'sales' column and applying mean() computes the average sales amount within each group. This directly satisfies the stem's requirement to aggregate average sales per region in a single chained pandas expression.

About these practice questions

This DA0-002 question is part of Courseiva's 1,004-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.