How to use tail() function In Python Pandas

Here tail() is used to remove the last n rows, to remove the first row, we have to use the shape function with -1 index.

Syntax:

data.tail(data.shape[0]-1)

where data is the input dataframe

Example: Drop the first row

Python3




# import pandas module
import pandas as pd
 
# create student dataframe with 3 columns
# and 4 rows
data = pd.DataFrame({'id': [1, 2, 3, 4],
                     'name': ['sai', 'navya', 'reema', 'thanuja'],
                     'age': [21, 22, 21, 22]})
 
 
# drop first row
data.tail(data.shape[0]-1)


Output:



How to Drop First Row in Pandas?

In this article, we will discuss how to drop the first row in Pandas Dataframe using Python.

Dataset in use:

Similar Reads

Method 1: Using iloc() function

Here this function is used to drop the first row by using row index....

Method 2: Using drop() function

...

Method 3: Using tail() function

Here we are using the drop() function to remove first row using the index parameter set to 0...

Contact Us