Open In App

How to append a list as a row to a Pandas DataFrame in Python?

Last Updated : 21 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, We are going to see how to append a list as a row to a pandas dataframe in Python. It can be done in three ways:

Prerequisite: Pandas DataFrame

1. Using loc[]

The loc[] method is used for label-based indexing. When you append a list as a row, the loc[] method allows us to specify the index to which we want to append the new data.

Step 1: Create a simple dataframe using the list.

Python
import pandas as pd

person = [ ['Satyam', 21, 'Patna' , 'India' ],
            ['Anurag', 23, 'Delhi' , 'India' ],
            ['Shubham', 27, 'Coimbatore' , 'India' ]]

df = pd.DataFrame(Person, 
                  columns = ['Name' , 'Age', 'City' , 'Country']) 

display(df)

Output:

Step 2: Using loc to append the new list to a data frame. 

Python
new_row = ["Saurabh", 23, "Delhi", "India"]

df.loc[len(df)] = new_row

display(df)

Output:

Explanation: df.loc[len(df)] = new_row appends the new row to the DataFrame, len(df) ensures that the new row is added to the next available index.

2. Using iloc[] method

iloc[] method is primarily used for integer-location based indexing. It is typically used for modifying or accessing data based on the row and column index positions, but we can also use it to update an existing row.

Example:

Python
import pandas as pd

# Create a sample DataFrame
person = [
    ['Satyam', 21, 'Patna', 'India'],
    ['Anurag', 23, 'Delhi', 'India'],
    ['Shubham', 27, 'Coimbatore', 'India'],
    ['Saurabh', 23, 'Delhi', 'India']
]

df = pd.DataFrame(person, columns=['Name', 'Age', 'City', 'Country'])

new_row = ['Ujjawal', 22, 'Fathua', 'India']

df.iloc[2] = new_row

display(df)

Output:

Explanation: we replace the third row (index 2) with new_row using df.iloc[2] = new_row.

Note: It is used for location-based indexing so it works for only the existing index and replaces the row element.

3. Using append() methods

Pandas dataframe.append() function is used to append rows of other dataframe to the end of the given dataframe, returning a new dataframe object.

Example:

Python
import pandas as pd

person = [
    ['Satyam', 21, 'Patna', 'India'],
    ['Anurag', 23, 'Delhi', 'India'],
    ['Shubham', 27, 'Coimbatore', 'India']
]

df = pd.DataFrame(person, columns=['Name', 'Age', 'City', 'Country'])

# New row to append
new_row = [["Manjeet", 25, "Delhi", "India"]]

# Append the new row using append()
df = df.append(pd.DataFrame(new_row, columns=['Name', 'Age', 'City', 'Country']), ignore_index=True)

display(df)

Output:

Explanation: we use df.append() to append the new row, and ignore_index=True ensures the new DataFrame gets a fresh index.

Note: append() returns a new DataFrame; it does not modify the original one.

Related Articles:


Next Article

Similar Reads