CBSE Class 12 Informatics Practices Question 42 of 101

Python Pandas — II — Question 18

Back to all questions
18
Question

Question 18

To get top 5 rows of a DataFrame, you may use ............... function.

  1. head()
  2. head(5)
  3. top()
  4. top(5)
Answer

head(), head(5)

Reason — The head() function in pandas is used to get the top n rows of a DataFrame, where n is an optional argument. If n is not provided, it defaults to 5. Hence, both head() and head(5) are correct and will return the top 5 rows of the DataFrame.