Add Column to Pandas DataFrame with a Default Value
Last Updated :
15 Jul, 2025
Let's discuss how to add column to Pandas DataFrame with a default value using assign(), the [] operator, and insert().
Add Column with a Default Value using assign()
The assign() method is used to add new columns to a DataFrame and returns a new object with all existing columns and the new ones. Existing columns that are re-assigned will be overwritten. This method allows you to set the default value for the new column as well.
DataFrame.assign(**kwargs)
Let's consider an example:
Python
# importing pandas as pd
import pandas as pd
# creating the dataframe
df = pd.DataFrame({"Name": ['Anurag', 'Manjeet', 'Shubham','Saurabh', 'Ujjawal'],
"Address": ['Patna', 'Delhi', 'Coimbatore','Greater noida', 'Patna'],
"ID": [20123, 20124, 20145, 20146, 20147],
"Sell": [140000, 300000, 600000, 200000, 600000]})
print("Original DataFrame :")
display(df)
Output:

Add a new column using assign()
Python
# Using assign() to add a 'profit' column
new_df = df.assign(profit=[40000, 20000, 30000, 60000, 200000])
print("\nDataFrame after using assign() to add 'profit' column:")
print(new_df)
Output:
DataFrame after using assign() to add 'profit' column:
Name Address ID Sell profit
0 Anurag Patna 20123 140000 40000
1 Manjeet Delhi 20124 300000 20000
2 Shubham Coimbatore 20145 600000 30000
3 Saurabh Greater noida 20146 200000 60000
4 Ujjawal Patna 20147 600000 200000
Add a new column with Default Value:
Python
# Using assign() to add a 'loss' column with a default value 'NAN'
new_df = df.assign(loss='NAN')
print("\nDataFrame after using assign() to add 'loss' column with default value:")
print(new_df)
Output:
Pandas DataFrame with a default valueAdding column to Pandas Dataframe using [] operator
The [] operator is the most straightforward method for adding a new column. You simply reference the column name and assign a value. This method allows you to assign both lists or scalar values.
df[col_name]=value
Let's use [] operator to add 'loss' column to the existing dataframe:
Python
# Using the [] operator to add a 'loss' column
df['loss'] = [40000, 20000, 30000, 60000, 200000]
print("\nDataFrame after using [] operator to add 'loss' column:")
print(df)
Output:

Adding a New Column with a Default Value:
Python
# Using the [] operator to add a 'loss' column with a default value 'NAN'
df['loss'] = 'NAN'
print("\nDataFrame after using [] operator to add 'loss' column with default value:")
print(df)
Output:
DataFrame after using [] operator to add 'loss' column with default value:
Name Address ID Sell loss
0 Anurag Patna 20123 140000 NAN
1 Manjeet Delhi 20124 300000 NAN
2 Shubham Coimbatore 20145 600000 NAN
3 Saurabh Greater noida 20146 200000 NAN
4 Ujjawal Patna 20147 600000 NAN
Using DataFrame.insert()
The insert() method adds a new column into a DataFrame at a specified location. This can be helpful if you need to control where the new column appears in the DataFrame.
DataFrame.insert(loc, column, value, allow_duplicates=False)
Let's understand with example:
Python
# Inserting a new column 'expenditure' at position 2
df.insert(2, "expenditure", 4500, allow_duplicates=False)
print("\nDataFrame after using insert() to add 'expenditure' column at position 2:")
print(df)
Output:
DataFrame after using insert() to add 'expenditure' column at position 2:
Name Address expenditure ID Sell loss
0 Anurag Patna 4500 20123 140000 NAN
1 Manjeet Delhi 4500 20124 300000 NAN
2 Shubham Coimbatore 4500 20145 600000 NAN
3 Saurabh Greater noida 4500 20146 200000 NAN
4 Ujjawal Patna 4500 20147 600000 NAN
Each of the methods discussed has its unique advantages:
- assign(): Ideal for adding new columns with a functional approach, especially when you want to return a modified copy of the DataFrame.
- [] operator: The simplest and most common method for quick modifications when you're working with DataFrames.
- insert(): Useful when you need to control the position of the new column.
How to Add New Column in Pandas Dataframe? | Pandas in Python
Explore
Introduction to Machine Learning
Python for Machine Learning
Introduction to Statistics
Feature Engineering
Model Evaluation and Tuning
Data Science Practice