Insert row at given position in Pandas Dataframe

Last Updated : 3 Oct, 2025

If a DataFrame has existing rows, you can insert a new row at any position without disturbing the other rows. For Example, suppose the DataFrame has [A, B, C] and you insert X at position 1, updated DataFrame becomes [A, X, B, C]

Let’s consider this DataFrame which we will use in all examples:

Python
import pandas as pd df = pd.DataFrame({ 'Date': ['10/2/2011', '12/2/2011', '13/2/2011', '14/2/2011'], 'Event': ['Music', 'Poetry', 'Theatre', 'Comedy'], 'Cost': [10000, 5000, 15000, 2000]}) print(df) 

Output

Date Event Cost
0 10/2/2011 Music 10000
1 12/2/2011 Poetry 5000
2 13/2/2011 Theatre 15000
3 14/2/2011 Comedy 2000

Examples

Example 1: In this example, we insert a row at position 2 using simple slicing and concat.

Python
new_row = ['11/2/2011', 'Wrestling', 12000] # Split the DataFrame upper = df[:2] lower = df[2:] # Combine upper, new row and lower df1 = pd.concat([upper, pd.DataFrame([new_row], columns=df.columns), lower]).reset_index(drop=True) print(df1) 

Output

Date Event Cost
0 10/2/2011 Music 10000
1 12/2/2011 Poetry 5000
2 11/2/2011 Wrestling 12000
3 13/2/2011 Theatre 15000
4 14/2/2011 Comedy 2000

Explanation:

  • upper = df[:2]: slice DataFrame to get rows before position 2.
  • lower = df[2:]: slice DataFrame to get rows from position 2 onward.
  • pd.concat([...]): combine upper, new row (converted to DataFrame), and lower.
  • .reset_index(drop=True): reset index to maintain consecutive integers.

Example 2: In this example, we insert a row at position 1 directly using loc.

Python
new_row2 = ['11/2/2011', 'Gymnastics', 11000] # Copy original DataFrame df2 = df.copy() # Insert row at position 1 df2.loc[1.5] = new_row2 df2 = df2.sort_index().reset_index(drop=True) print(df2) 

Output

Date Event Cost
0 10/2/2011 Music 10000
1 12/2/2011 Poetry 5000
2 11/2/2011 Gymnastics 11000
3 13/2/2011 Theatre 15000
4 14/2/2011 Comedy 2000

Explanation:

  • df2 = df.copy(): create a copy of the original DataFrame to avoid changes.
  • df2.loc[1.5] = new_row2: insert row at a temporary fractional index.
  • df2.sort_index().reset_index(drop=True): sort by index and reset to maintain integer order.

Example 3: In this example, we insert a new row at the end of the DataFrame using loc.

Python
row_value3 = ['15/2/2011', 'Dance', 9000] # Insert at the end df3 = df.copy() df3.loc[df3.shape[0]] = row_value3 print(df3) 

Output

Date Event Cost
0 10/2/2011 Music 10000
1 12/2/2011 Poetry 5000
2 13/2/2011 Theatre 15000
3 14/2/2011 Comedy 2000
4 15/2/2011 Dance 9000

Explanation:

  • df3 = df.copy(): copy original DataFrame.
  • df3.loc[df3.shape[0]] = row3: insert row at the next available index (end).

Explore