How to delete the first three rows of a DataFrame in Pandas?

Given a Pandas DataFrame, we have to delete the first three rows.
Submitted by Pranit Sharma, on May 27, 2022

Rows in pandas are the different cell (column) values that are aligned horizontally and also provide uniformity. Each row can have the same or different value. Rows are generally marked with the index number but in pandas, we can also assign index names according to the needs. In pandas, we can create, read, update and delete a column or row value.

Here, we are going to learn how to delete the first three rows of a pandas DataFrame?

For this, we are going to use DataFrame.iloc() method to directly slice the DataFrame after the first three rows.

To work with pandas, we need to import pandas package first, below is the syntax:

import pandas as pd

Let us understand with the help of an example.

# Importing pandas package
import pandas as pd

# creating a dictionary of student marks
d = {

# Now we will create DataFrame
df = pd.DataFrame(d)

# Viewing the DataFrame

# Excluding first three rows
result = df.iloc[3:]

# Display resulted dataframe
print("DataFrame after excluding first 3 rows\n",result)


Example: Delete the first three rows of a DataFrame

Python Pandas Programs »


What's New (MCQs)

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.