1. Home
  2. Data Science
  3. Pandas
  4. What does df["price"] return for a DataFrame df in pandas?

Added 30 Nov -0001

What does df["price"] return for a DataFrame df in pandas?

  1. A NumPy array holding the column values
  2. The column's dtype object
  3. A Series holding that single column Correct answer
  4. A DataFrame with one column

Correct answer

C. A Series holding that single column

13 views

MCQSEXAM

Explanation

Bracket selection with a single label returns a Series, a one-dimensional labelled array whose index is the DataFrame's row index. Selecting with a list, df[["price"]], returns a DataFrame instead, which matters when downstream code expects two dimensions. Use .to_numpy() explicitly if a raw NumPy array is required, since pandas does not return one implicitly.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs