Let’s discuss how to add new columns to the existing DataFrame in Pandas. There are multiple ways we can do this task.
Method #1: By declaring a new list as a column.
Python3
import pandas as pd
data = { 'Name' : [ 'Jai' , 'Princi' , 'Gaurav' , 'Anuj' ],
'Height' : [ 5.1 , 6.2 , 5.1 , 5.2 ],
'Qualification' : [ 'Msc' , 'MA' , 'Msc' , 'Msc' ]}
df = pd.DataFrame(data)
address = [ 'Delhi' , 'Bangalore' , 'Chennai' , 'Patna' ]
df[ 'Address' ] = address
print (df)
|
Output:

Note that the length of your list should match the length of the index column otherwise it will show an error.
Method #2: By using DataFrame.insert()
It gives the freedom to add a column at any position we like and not just at the end. It also provides different options for inserting the column values.
Example
Python3
import pandas as pd
data = { 'Name' : [ 'Jai' , 'Princi' , 'Gaurav' , 'Anuj' ],
'Height' : [ 5.1 , 6.2 , 5.1 , 5.2 ],
'Qualification' : [ 'Msc' , 'MA' , 'Msc' , 'Msc' ]}
df = pd.DataFrame(data)
df.insert( 2 , "Age" , [ 21 , 23 , 24 , 21 ], True )
print (df)
|
Output:

Method #3: Using Dataframe.assign() method
This method will create a new dataframe with a new column added to the old dataframe.
Example
Python3
import pandas as pd
data = { 'Name' : [ 'Jai' , 'Princi' , 'Gaurav' , 'Anuj' ],
'Height' : [ 5.1 , 6.2 , 5.1 , 5.2 ],
'Qualification' : [ 'Msc' , 'MA' , 'Msc' , 'Msc' ]}
df = pd.DataFrame(data)
df2 = df.assign(address = [ 'Delhi' , 'Bangalore' , 'Chennai' , 'Patna' ])
print (df2)
|
Output:

Method #4: By using a dictionary
We can use a Python dictionary to add a new column in pandas DataFrame. Use an existing column as the key values and their respective values will be the values for a new column.
Example
Python3
import pandas as pd
data = { 'Name' : [ 'Jai' , 'Princi' , 'Gaurav' , 'Anuj' ],
'Height' : [ 5.1 , 6.2 , 5.1 , 5.2 ],
'Qualification' : [ 'Msc' , 'MA' , 'Msc' , 'Msc' ]}
address = { 'Delhi' : 'Jai' , 'Bangalore' : 'Princi' ,
'Patna' : 'Gaurav' , 'Chennai' : 'Anuj' }
df = pd.DataFrame(data)
df[ 'Address' ] = address
print (df)
|
Output:
