VOOZH about

URL: https://www.geeksforgeeks.org/pandas/how-to-drop-first-row-in-pandas/

⇱ How to Drop First Row in Pandas? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Drop First Row in Pandas?

Last Updated : 20 Mar, 2026

A DataFrame is given and the task is to remove the first row from it. For example, consider the following DataFrame:

Input: A B
0 1 2
1 3 4

Output: A B
1 3 4

Let's explore different methods to drop first row.

Using iloc for Index-Based Selection

iloc is used to select data based on integer (position-based) indexing in a DataFrame. It allows to access rows and columns using their index positions. To drop the first row using iloc, select all rows starting from index 1:


Output
 name age
1 Kate 22
2 Nancy 21
3 Emilia 22

Explanation:

  • slice [1:] selects rows starting from index 1.
  • All remaining rows are selected and printed.

Using drop() Method

In this method, the index of the row (typically 0) is specified and the drop() method is used with the index parameter set to 0. To modify the original DataFrame directly, the inplace=True argument is used.


Output
 name age
1 Kate 22
2 Nancy 21
3 Emilia 22

Explanation:

  • First row is selected using data.index[0].
  • axis=0 specifies that a row is being removed.
  • inplace=True argument applies the change directly to the original DataFrame.

Using loc

loc is used to drop the first row by selecting data based on index labels instead of positions. By starting the selection from the second label onward, it excludes the first row from the DataFrame.


Output
 name age
20 Kate 22
30 Nancy 21
40 Emilia 22

Explanation:

  • index is changed to custom labels [10, 20, 30, 40].
  • loc[20:] selects rows starting from label 20.
  • iloc[1:] selects rows starting from position 1 (second row).

Using tail() Function

The tail() function is used to drop the first row by selecting all rows except the first based on count. By taking the last n-1 rows, it excludes the first row from the DataFrame.


Output
 name age
1 Kate 22
2 Nancy 21
3 Emilia 22

Explanation:

  • shape[0] gives the total number of rows.
  • tail(d.shape[0] - 1) selects all rows except the first.
Comment

Explore