Javatpoint Logo
Javatpoint Logo

Pandas DataFrame.assign()

The assign() method is also responsible for adding a new column into a DataFrame.

If we re-assign an existing column, then its value will be overwritten.



  • kwargs: keywords are the column names. These keywords are assigned to the new column if the values are callable. If the values are not callable, they are simply assigned.


It returns a new DataFrame with the addition of the new columns.

Example 1:


     ID     Name
0    101    Smith
1    102	Parker
2    103	John

Example 2:


            temp_c     temp_f     temp_k
Canada       17.0       72.0     621.405
Australia    25.0       96.0     657.405

Next TopicDataFrame.astype()

Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA