Skip to main contentSkip to solution

What is the correct syntax for extracting the last three rows of the DataFrame 'df'?

Solution

✅ Correct Option: 2

df.tail(n) is the dedicated pandas method that returns the last n rows of a DataFrame, so df.tail(3) returns the last three rows.


Option 4: a negative n in tail means "all rows except the first n", so df.tail(-3) drops the first three rows instead.


We believe the answer could also be Option 1 or Option 3, since df.iloc[-3:] and df[-3:] also return the last three rows through negative slicing. However, NTA's final answer key (after all challenges) says Option 2.

Keyboard Shortcuts

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