Skip to main contentSkip to solution

Given the following DataFrame 'df':

PNONAME
111ROHAN
222MEETA
333SEEMA
444SHALU
555POONAM

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

(A) print(df.tail(-5))

(B) print(df.head(-5))

(C) print(df.tail())

(D) print(df.tail(5))

Solution

✅ Correct Option: 4

df.tail() returns the last 5 rows by default, and df.tail(5) asks for the last 5 rows explicitly. The DataFrame has exactly 5 rows, so both commands display all of them.


(A) and (B): a negative n does not give the last five rows. df.tail(-5) returns all rows except the first 5, and df.head(-5) returns all rows except the last 5. With only 5 rows, both print an empty DataFrame.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question