Hitesh wants to display the last four rows of the dataframedf and has written the following code : df.tail() But last 5 rows are being displayed. Identify the error and rewrite the correct code so that last 4 rows get displayed.
Answers
Answered by
42
Hitesh wants to display the last four rows of the data frame df and has written the following code: df .tail(). The error in this code is that he has not specified the number of rows he wants.
- df.tail() by default returns 5 rows of the data frame from the last.
- So if he writes df.tail() without specifying the number of rows he wants, he will get 5 rows by default.
- The correct way to return 4 rows is: df .tail(4)
- Here, after the specifying 4 in the bracket, only 4 rows from the end of the data frame will be returned.
Similar questions