How to append a list as a row to a Pandas DataFrame in Python?
Prerequisite: Pandas DataFrame
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:
Append list using loc methods
Pandas DataFrame.loc attribute access a group of rows and columns by label(s) or a boolean array in the given DataFrame.
Let’s append the list with step-wise:
Step 1: Create a simple dataframe using the list.
Step 2: Using loc to append the new list to a data frame.
Append list using iloc methods
Pandas DataFrame.iloc method access integer-location based indexing for selection by position.
Note – It is used for location-based indexing so it works for only existing index and replaces the row element.
Append list 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.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course