Tutorials References Exercises Sign Up Menu
Create Website Get Certified Pro

Pandas DataFrame assign() Method

❮ DataFrame Reference


Add a new column to the DataFrame:

import pandas as pd

data = {
  "age": [16, 14, 10],
  "qualified": [True, True, True]
df = pd.DataFrame(data)

newdf = df.assign(name = ["Emil", "Tobias", "Linus"])
Try it Yourself »

Definition and Usage

The assign() method adds a new column to an existing DataFrame.




Parameter Description
kwargs Required. The new column name(s) with values

Return Value

A DataFrame with the new column(s) added.

This method does not change the original DataFrame.

❮ DataFrame Reference