CBSE Class 12 Informatics Practices Question 99 of 167

Python Pandas — I — Question 10

Back to all questions
10
Question

Question 10

Hitesh wants to display the last four rows of the dataframe df 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.

Answer

The error in Hitesh's code is that the tail() function in pandas by default returns the last 5 rows of the dataframe. To display the last 4 rows, Hitesh needs to specify the number of rows he wants to display.

Here's the correct code:

df.tail(4)