Treating the identifiers inside parentheses as a parameter-name listing, which…

2023

Treating the identifiers inside parentheses as a parameter-name listing, which option uses the documented pandas.DataFrame capitalization and lists only documented constructor parameter names?

Answer: D. pandas.DataFrame(data, index, dtype, copy)Concept — a Python class is called by writing its name exactly as the library exports it, then supplying arguments drawn from that class's documented…

  1. A.

    pandas.DataFrame(data, index, col, dtype, copy)

  2. B.

    pandas.DataFrame(data, index, row, dtype, copy)

  3. C.

    pandas.dataFrame(data, index, dtype, copy)

  4. D.

    pandas.DataFrame(data, index, dtype, copy)

Attempted by 1288 students.

Show answer & explanation

Correct answer: D

Concept — a Python class is called by writing its name exactly as the library exports it, then supplying arguments drawn from that class's documented parameter list. Two independent conditions must hold at the same time: attribute lookup in Python is case-sensitive, so the exported spelling must match character for character; and every parameter you name must actually appear in the documented signature. Either condition alone is not enough.

The pandas reference documents the constructor as:

pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=None)

What each parameter carries

  • data — the values that populate the frame

  • index — the row labels

  • columns — the column labels

  • dtype — a data type to force on the result

  • copy — whether the input data is copied

Application — test each printed form against the two conditions.

  1. The form written as pandas.dataFrame(data, index, dtype, copy) fails the spelling condition. pandas exports the class as DataFrame, with a capital D and a capital F, so a lowercase d raises AttributeError.

  2. The form listing col names a parameter that has no entry in the signature above. The column-label parameter is spelled columns in full; pandas accepts no abbreviated alias for it.

  3. The form listing row names a parameter that has no entry either. Row labels are supplied through index.

  4. The form pandas.DataFrame(data, index, dtype, copy) spells the class name as pandas exports it, and every name it lists — data, index, dtype, copy — appears in the documented signature. This is the form recorded as the answer in the official EMRS 2023 key.

Cross-check — one nuance is worth stating plainly. That form omits columns, so read as a strictly positional call its third and fourth arguments would bind to columns and dtype rather than to dtype and copy. It is best read as a partial listing of valid parameter names rather than as a literal positional call. Because columns is optional — it defaults to None, and pandas derives the column labels from the data when it is not supplied — that listing is still the only one of the four printed forms in which both conditions hold.

Result — the constructor is pandas.DataFrame(...), and its documented parameters are data, index, columns, dtype and copy.

Explore the full course: Hpsc Pgt Computer Science

Loading lesson…