Tutorials References Exercises Sign Up Menu
Create Website Get Certified Pro

Pandas DataFrame insert() Method

❮ DataFrame Reference


Insert a new column with age of each member, and place it between "name" and "qualified":

import pandas as pd

data = {
  "name": ["Sally", "Mary", "John"],
  "qualified": [True, False, False]

df = pd.DataFrame(data)

df.insert(1, "age", [50, 40, 30])

Try it Yourself »

Definition and Usage

The insert() method allows us to insert a new column to an existing DataFrame.


dataframe.insert(loc, column, value, allow_duplicates)


Parameter Description
loc Required. An integer specifying the location of the new column.
columns Required. A string specifying the name of the new column.
value Required. An array-like object specifying the values of the new column.
allow_duplicates Optional. Default False, specifying whether the DataFrame allows columns with the same name or not.

Return Value

None. The insertion is done in the original DataFrame.

❮ DataFrame Reference