w3resource

Pandas DataFrame: assign() function

DataFrame - assign() function

The assign() function is used to assign new columns to a DataFrame.

Returns a new object with all original columns in addition to new ones. Existing columns that are re-assigned will be overwritten.

Syntax:

DataFrame.assign(self, **kwargs)

Parameters:

Name Description Type/Default Value Required / Optional
**kwargs The column names are keywords. If the values are callable, they are computed on the DataFrame and assigned to the new columns. The callable must not change input DataFrame (though pandas doesn't check it). If the values are not callable, (e.g. a Series, scalar, or array), they are simply assigned. dict of {str: callable or Series} Required

Returns: DataFrame
A new DataFrame with the new columns in addition to all the existing columns.

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - append() function
Next: DataFrame - join() function



Follow us on Facebook and Twitter for latest update.