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



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/pandas/dataframe/dataframe-assign.php