Question:medium

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: Feb 16, 2026
  • print(df.tail(-5))
  • print(df.head(-5))
  • print(df.tail())
  • print(df.tail(5))
Show Solution

The Correct Option is C

Solution and Explanation

Step 1: Review DataFrame retrieval commands.
- \texttt{df.tail()} → Retrieves the last 5 rows by default.
- \texttt{df.tail(n)} → Retrieves the last $n$ rows. Thus, \texttt{df.tail(5)} also yields the last 5 rows.
Step 2: Assess provided options.
- (A) \texttt{df.tail(-5)} → Invalid: Negative values are disallowed.
- (B) \texttt{df.head(-5)} → Invalid: Negative indexing is not supported.
- (C) \texttt{df.tail()} → Valid: Returns the last 5 rows.
- (D) \texttt{df.tail(5)} → Valid: Explicitly returns the last 5 rows.

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


Questions Asked in CUET (UG) exam