KnowledgeBoat Logo
|
LoginJOIN NOW

Informatics Practices

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.

Python Pandas

6 Likes

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)

Answered By

2 Likes


Related Questions