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…
- A.
pandas.DataFrame(data, index, col, dtype, copy)
- B.
pandas.DataFrame(data, index, row, dtype, copy)
- C.
pandas.dataFrame(data, index, dtype, copy)
- 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 frameindex— the row labelscolumns— the column labelsdtype— a data type to force on the resultcopy— whether the input data is copied
Application — test each printed form against the two conditions.
The form written as
pandas.dataFrame(data, index, dtype, copy)fails the spelling condition. pandas exports the class asDataFrame, with a capital D and a capital F, so a lowercase d raisesAttributeError.The form listing
colnames a parameter that has no entry in the signature above. The column-label parameter is spelledcolumnsin full; pandas accepts no abbreviated alias for it.The form listing
rownames a parameter that has no entry either. Row labels are supplied throughindex.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.