88
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.
Signature
Parameters
- 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.
Returns
It returns a new DataFrame with the addition of the new columns.
Example 1:
Output
ID Name 0 101 Smith 1 102Parker 2 103John
Example 2:
Output
temp_c temp_f temp_k Canada 17.0 72.0 621.405 Australia 25.0 96.0 657.405
Next TopicDataFrame.astype()