Let’s discuss how to add new columns to existing DataFrame in Pandas. There are multiple ways we can do this task.
Method #1: By declaring a new list as a column.
# Import pandas package import pandas as pd # Define a dictionary containing Students data data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'], 'Height': [5.1, 6.2, 5.1, 5.2], 'Qualification': ['Msc', 'MA', 'Msc', 'Msc']} # Convert the dictionary into DataFrame df = pd.DataFrame(data) # Declare a list that is to be converted into a column address = ['Delhi', 'Bangalore', 'Chennai', 'Patna'] # Using 'Address' as the column name # and equating it to the list df['Address'] = address # Observe the result 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.
# Import pandas package import pandas as pd # Define a dictionary containing Students data data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'], 'Height': [5.1, 6.2, 5.1, 5.2], 'Qualification': ['Msc', 'MA', 'Msc', 'Msc']} # Convert the dictionary into DataFrame df = pd.DataFrame(data) # Using DataFrame.insert() to add a column df.insert(2, "Age", [21, 23, 24, 21], True) # Observe the result df |
Output:

Method #3: Using Dataframe.assign() method
This method will create a new dataframe with new column added to the old dataframe.
# Import pandas package import pandas as pd # Define a dictionary containing Students data data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'], 'Height': [5.1, 6.2, 5.1, 5.2], 'Qualification': ['Msc', 'MA', 'Msc', 'Msc']} # Convert the dictionary into DataFrame df = pd.DataFrame(data) # Using 'Address' as the column name and equating it to the list df2 = df.assign(address = ['Delhi', 'Bangalore', 'Chennai', 'Patna']) # Observe the result 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 new column.
# Import pandas package import pandas as pd # Define a dictionary containing Students data data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'], 'Height': [5.1, 6.2, 5.1, 5.2], 'Qualification': ['Msc', 'MA', 'Msc', 'Msc']} # Define a dictionary with key values of # an existing column and their respective # value pairs as the # values for our new column. address = {'Delhi': 'Jai', 'Bangalore': 'Princi', 'Patna': 'Gaurav', 'Chennai': 'Anuj'} # Convert the dictionary into DataFrame df = pd.DataFrame(data) # Provide 'Address' as the column name df['Address'] = address # Observe the output df |
Output:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Create a new column in Pandas DataFrame based on the existing columns
- How to add one row in an existing Pandas DataFrame?
- Convert given Pandas series into a dataframe with its index as another column on the dataframe
- Get column index from column name of a given Pandas DataFrame
- Create a Pandas DataFrame from a Numpy array and specify the index column and column headers
- Create a DataFrame from a Numpy array and specify the index column and column headers
- Add a new column in Pandas Data Frame Using a Dictionary
- How to Add Group-Level Summary Statistic as a New Column in Pandas?
- Python | Pandas DataFrame.fillna() to replace Null values in dataframe
- Pandas Dataframe.to_numpy() - Convert dataframe to Numpy array
- How to get column names in Pandas dataframe
- Capitalize first letter of a column in Pandas dataframe
- Python | Change column names and row indexes in Pandas DataFrame
- Convert the column type from string to datetime format in Pandas dataframe
- Apply uppercase to a column in Pandas dataframe
- How to lowercase column names in Pandas dataframe
- Get unique values from a column in Pandas DataFrame
- Get n-smallest values from a particular column in Pandas DataFrame
- Get n-largest values from a particular column in Pandas DataFrame
- Split a text column into two columns in Pandas DataFrame
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
