Open In App

Add a row at top in pandas DataFrame

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Pandas DataFrame is two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). 
Let's see how can we can add a row at top in pandas DataFrame.
Observe this dataset first.
 

Python3
# importing pandas module 
import pandas as pd 
  
# making data frame 
df = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv") 

df.head(10)

Code #1: Adding row at the top of given dataframe by concatenating the old dataframe with new one. 
 

Python3
new_row = pd.DataFrame({'Name':'Geeks', 'Team':'Boston', 'Number':3,
                        'Position':'PG', 'Age':33, 'Height':'6-2',
                        'Weight':189, 'College':'MIT', 'Salary':99999},
                                                            index =[0])
# simply concatenate both dataframes
df = pd.concat([new_row, df]).reset_index(drop = True)
df.head(5)

Output: 
 


  
Code #2: Adding row at the top of given dataframe by concatenating the old dataframe with new one. 
 

Python3
new_row = pd.DataFrame({'Name':'Geeks', 'Team':'Boston', 'Number':3,
                        'Position':'PG', 'Age':33, 'Height':'6-2',
                        'Weight':189, 'College':'MIT', 'Salary':99999}, index =[0])

# Concatenate new_row with df 
df = pd.concat([new_row, df[:]]).reset_index(drop = True)
df.head(5)

Output: 
 


  
Code #3: Adding row at the top of given dataframe by concatenating the old dataframe with new one using df.ix[] method.
 

Python3
new_row = pd.DataFrame({'Name':'Geeks', 'Team':'Boston', 'Number':3,
                        'Position':'PG', 'Age':33, 'Height':'6-2',
                        'Weight':189, 'College':'MIT', 'Salary':99999}, index =[0])

df = pd.concat([new_row, df.ix[:]]).reset_index(drop = True)
df.head(5)

Output: 
 


 


Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy