What is the correct syntax for extracting the last three rows of the DataFrame 'df'?
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.
Related questions:
2026: 31 May Shift 1
2025: 20 May Shift 1
2026: 23 May Shift 1