1. Home
  2. Data Science
  3. Pandas
  4. Which pandas expression returns the number of rows in a…

Added 30 Nov -0001

Which pandas expression returns the number of rows in a DataFrame df?

  1. len(df) Correct answer
  2. df.size
  3. df.columns
  4. df.ndim

Correct answer

A. len(df)

16 views

MCQSEXAM

Explanation

len(df) returns the number of rows because Python's length protocol is mapped to the frame's first axis. df.size instead multiplies rows by columns and gives the total number of cells, while df.ndim is 2 for any DataFrame. The explicit alternatives are df.shape[0] and the index's length, which agree unless the index contains duplicate labels.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? 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