Given the following DataFrame 'df':
PNO NAME 111 ROHAN 222 MEETA 333 SEEMA 444 SHALU 555 POONAM
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))
Given the following DataFrame 'df':
| PNO | NAME |
|---|---|
| 111 | ROHAN |
| 222 | MEETA |
| 333 | SEEMA |
| 444 | SHALU |
| 555 | POONAM |
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.
Related questions:
2025: 21 May Shift 1
2026: 23 May Shift 1
2026: 29 May Shift 2
2026: 26 May Shift 1