Question:

Given the following DataFrame df:

PNONAME
111ROHAN
222MEETA
333SEEMA
444SHALU
555POONAM

Select the correct commands from the following to display the last five rows:

Show Hint

Use \texttt{df.head(n)} for first $n$ rows and \texttt{df.tail(n)} for last $n$ rows. Default $n=5$.
Updated On: Sep 18, 2025
  • print(df.tail(-5))
  • print(df.head(-5))
  • print(df.tail())
  • print(df.tail(5))
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Recall DataFrame commands.
- \texttt{df.tail()} → returns the last 5 rows by default.
- \texttt{df.tail(n)} → returns the last $n$ rows. So \texttt{df.tail(5)} also gives the last 5 rows.
Step 2: Evaluate given options.
- (A) \texttt{df.tail(-5)} → Invalid, negative values are not allowed.
- (B) \texttt{df.head(-5)} → Invalid, negative index not supported.
- (C) \texttt{df.tail()} → Correct, gives last 5 rows.
- (D) \texttt{df.tail(5)} → Correct, explicitly gives last 5 rows.

Step 3: Conclusion.
The correct commands are (C) and (D).
Final Answer: \[ \boxed{\text{(C) and (D) only}} \]
Was this answer helpful?
0
0

Questions Asked in CUET exam

View More Questions