Pandas Dataframe.assign() method assigns new columns to a DataFrame, returning the new object (a copy) with the new columns added to the original ones. Please be careful while assigning the new columns because existing columns that are re-assigned will be overwritten.

Pandas assign example

To assign new columns to a DataFrame, use the Pandas assign() method. The assign() returns the new object with all original columns in addition to new ones. Existing columns that are re-assigned will be overwritten. The length of the newly assigned column must match the number of rows in the  DataFrame.

Syntax

DataFrame.assign(**kwargs)

#pandas #python

Pandas Assign: How to Assign New Columns to DataFrame
1.05 GEEK