Courseiva

DA0-002 Data Acquisition and Preparation Practice Question

A data analyst is using pandas to read a CSV file named 'sales.csv'. Which line of code correctly reads the file into a DataFrame?

⚠ Common exam trap

The trap is that all four options look syntactically plausible — candidates who don't actually use pandas daily may pick pd.read() or np.read_csv() because they sound reasonable, but only read_csv is the real API.

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

✓

import pandas as pd; df = pd.read_csv('sales.csv')

The correct pandas idiom is pd.read_csv('sales.csv'), which returns a DataFrame. pandas is conventionally imported as pd, and read_csv is the dedicated CSV parser that handles delimiters, headers, dtypes, and encoding. This is the canonical one-liner every pandas user writes.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    import csv; df = csv.read('sales.csv')

    Why it's wrong here

    The csv module has no read function returning a DataFrame; it exposes reader and DictReader yielding rows, so this line raises an AttributeError. It is tempting because the csv module genuinely parses CSV files, and would be correct for lightweight row-by-row processing without pandas.

  • ✗

    import pandas as pd; df = pd.read('sales.csv')

    Why it's wrong here

    pandas exposes read_csv, not read; pd.read does not exist, so this raises an AttributeError rather than loading the file. It is tempting because the import and DataFrame assignment are otherwise correct, and read_csv is the genuine pandas function for this task.

  • ✗

    import numpy as np; df = np.read_csv('sales.csv')

    Why it's wrong here

    NumPy provides no read_csv function; genfromtxt and loadtxt handle delimited text but return arrays, not DataFrames. It is tempting because NumPy underpins pandas and is genuinely used for numeric array loading, which would suit pure numerical computation without labelled columns.

  • ✓

    import pandas as pd; df = pd.read_csv('sales.csv')

    Why this is correct

    `pd.read_csv('sales.csv')` is pandas' dedicated CSV parser, returning a DataFrame directly from the file path. The import aliases pandas as `pd`, satisfying the stem's requirement to read `sales.csv` into a DataFrame in one line, with no extra arguments needed for a standard comma-delimited file.

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 →

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.