How to use iloc() function In Python Pandas

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

Syntax:

df.iloc[row_start:row_end , column_start:column_end]

where,

  • row_start  specifies first row
  • row_end specifies last row
  • column_start specifies first column
  • column_end specifies last column

We can drop the first row by excluding the first row 

Syntax:

data.iloc[1: , :]

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.iloc[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