![]() |
VOOZH | about |
In Pandas, we have the freedom to add columns in the data frame whenever needed. There are multiple ways to add columns to pandas dataframe.
Output :
Using DataFrame.assign() method, we can set column names as parameters and pass values as list to replace/create the columns.
Output :
Using DataFrame.insert() method, we can add new columns at specific position of the column name sequence. Although insert takes single column name, value as input, but we can use it repeatedly to add multiple columns to the DataFrame.
Output :
Using Dict and zip() we can create a mapping of key values, which can be assigned to a new column name.
Output :