Columns are the different fields which contains their particular values when we create a DataFrame. We can perform certain operations on both rows & column values. Sometimes we might need to insert a particular column at a specific index. We can achieve this task using pandas.DataFrame.insert() method.
pandas.DataFrame.insert() Method
This method is used to insert a new column in a DataFrame manually, below is the syntax:
DataFrame.insert(
loc,
column,
value,
allow_duplicates=False
)
# or
DataFrame.insert(loc='', column='')
Parameter(s):
- It takes a parameter loc which means the index where to inert the column.
- It takes another parameter column which is used to assign a name to the new column.
To work with pandas, we need to import pandas package first, below is the syntax:
import pandas as pd
Let us understand with the help of an example:
Output:

need an explanation for this answer? contact us directly to get an explanation for this answer