Super simple in-place assignment: df['new'] = 0

For in-place modification, perform direct assignment. This assignment is broadcasted by pandas for each row.

df = pd.DataFrame('x', index=range(4), columns=list('ABC'))
df

   A  B  C
0  x  x  x
1  x  x  x
2  x  x  x
3  x  x  x

df['new'] = 'y'
# Same as,
# df.loc[:, 'new'] = 'y'
df

   A  B  C new
0  x  x  x   y
1  x  x  x   y
2  x  x  x   y
3  x  x  x   y

Note for object columns

If you want to add an column of empty lists, here is my advice:

  • Consider not doing this. object columns are bad news in terms of performance. Rethink how your data is structured.
  • Consider storing your data in a sparse data structure. More information: sparse data structures
  • If you must store a column of lists, ensure not to copy the same reference multiple times.

    # Wrong
    df['new'] = [[]] * len(df)
    # Right
    df['new'] = [[] for _ in range(len(df))]
    

Generating a copy: df.assign(new=0)

If you need a copy instead, use DataFrame.assign:

df.assign(new='y')

   A  B  C new
0  x  x  x   y
1  x  x  x   y
2  x  x  x   y
3  x  x  x   y

And, if you need to assign multiple such columns with the same value, this is as simple as,

c = ['new1', 'new2', ...]
df.assign(**dict.fromkeys(c, 'y'))

   A  B  C new1 new2
0  x  x  x    y    y
1  x  x  x    y    y
2  x  x  x    y    y
3  x  x  x    y    y

Multiple column assignment

Finally, if you need to assign multiple columns with different values, you can use assign with a dictionary.

c = {'new1': 'w', 'new2': 'y', 'new3': 'z'}
df.assign(**c)

   A  B  C new1 new2 new3
0  x  x  x    w    y    z
1  x  x  x    w    y    z
2  x  x  x    w    y    z
3  x  x  x    w    y    z
Answer from coldspeed95 on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ add-zero-columns-to-pandas-dataframe
Add zero columns to Pandas Dataframe - GeeksforGeeks
2 weeks ago - # import pandas library import pandas as pd # creating dictionary of lists dict = {'name': ["sohom", "rakesh", "rajshekhar", "sumit"], 'department': ["ECE", "CSE", "EE", "MCA"], 'CGPA': [9.2, 8.7, 8.6, 7.7]} # creating a dataframe df = pd.DataFrame(dict) print("data frame before adding the column:") display(df) # creating a new column # of zeroes to the # dataframe df['new'] = 0 # showing the dataframe print("data frame after adding the column:") display(df)
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ python-add-a-zero-column-to-pandas-dataframe
Python - Add a zero column to Pandas DataFrame
March 26, 2026 - Adding a zero column to a Pandas DataFrame is straightforward using dataFrame['column_name'] = 0.
Discussions

python - Add column with constant value to pandas dataframe - Stack Overflow
@joris, I meant that df['new']=0 ... zeros to the whole column, but it doesn't explain why my first attempt inserts NaN. This was answered by the Philip Cloud in the answer I accepted. ... Save this answer. ... Show activity on this post. For in-place modification, perform direct assignment. This assignment is broadcasted by pandas for each row. Copydf = pd.DataFrame('x', ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Add multiple columns with zero values from a list to a Pandas data frame - Stack Overflow
Say I have a data frame id col1 col2 1 1 foo 2 1 bar And a list of column names l = ['col3', 'col4', 'col5'] How do I add new columns to the data frame with zero as values? id col1 col2... More on stackoverflow.com
๐ŸŒ stackoverflow.com
April 30, 2018
python - How to add column to df with zero array - Stack Overflow
It seems like it is trying to append ... be a zero matrix. Apologies if I didn't format the question correctly, I am new to this site. ... Do you want to add 20 more columns with 0s or do you want to add one column that contains a list with 20 0s per each row? ... Save this answer. Show activity on this post. Pandas tries to broadcast the numpy array to fit your dataframe in ways that ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
pandas - how to create all zero dataframe in Python - Stack Overflow
I want to create a dataframe in Python with 24 columns (indicating 24 hours), which looks like this: column name 0 1 2 3 ... 24 row 1 0 0 0 0 0 row 2 ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 5 best ways to add a zero column to a pandas dataframe
5 Best Ways to Add a Zero Column to a Pandas DataFrame - Be on the Right Side of Change
March 4, 2024 - This snippet uses df.assign(C=0) to add a new zero-filled column โ€˜Cโ€™ to the DataFrame โ€˜dfโ€™. One advantage of this approach is that it returns a new DataFrame, which can be useful if you want to maintain the original DataFrame unchanged.
Top answer
1 of 4
221

Super simple in-place assignment: df['new'] = 0

For in-place modification, perform direct assignment. This assignment is broadcasted by pandas for each row.

df = pd.DataFrame('x', index=range(4), columns=list('ABC'))
df

   A  B  C
0  x  x  x
1  x  x  x
2  x  x  x
3  x  x  x

df['new'] = 'y'
# Same as,
# df.loc[:, 'new'] = 'y'
df

   A  B  C new
0  x  x  x   y
1  x  x  x   y
2  x  x  x   y
3  x  x  x   y

Note for object columns

If you want to add an column of empty lists, here is my advice:

  • Consider not doing this. object columns are bad news in terms of performance. Rethink how your data is structured.
  • Consider storing your data in a sparse data structure. More information: sparse data structures
  • If you must store a column of lists, ensure not to copy the same reference multiple times.

    # Wrong
    df['new'] = [[]] * len(df)
    # Right
    df['new'] = [[] for _ in range(len(df))]
    

Generating a copy: df.assign(new=0)

If you need a copy instead, use DataFrame.assign:

df.assign(new='y')

   A  B  C new
0  x  x  x   y
1  x  x  x   y
2  x  x  x   y
3  x  x  x   y

And, if you need to assign multiple such columns with the same value, this is as simple as,

c = ['new1', 'new2', ...]
df.assign(**dict.fromkeys(c, 'y'))

   A  B  C new1 new2
0  x  x  x    y    y
1  x  x  x    y    y
2  x  x  x    y    y
3  x  x  x    y    y

Multiple column assignment

Finally, if you need to assign multiple columns with different values, you can use assign with a dictionary.

c = {'new1': 'w', 'new2': 'y', 'new3': 'z'}
df.assign(**c)

   A  B  C new1 new2 new3
0  x  x  x    w    y    z
1  x  x  x    w    y    z
2  x  x  x    w    y    z
3  x  x  x    w    y    z
2 of 4
64

With modern pandas you can just do:

df['new'] = 0
๐ŸŒ
Like Geeks
likegeeks.com โ€บ home โ€บ python โ€บ pandas โ€บ add a row of zeros to a pandas dataframe
Add a Row of Zeros to a Pandas DataFrame
July 6, 2024 - Letโ€™s explore each of these scenarios using our ongoing telecom data example. If you want to insert a row at the top of your DataFrame, you can achieve this by resetting the index.
๐ŸŒ
DataScience Made Simple
datasciencemadesimple.com โ€บ home โ€บ add leading zeros in python pandas (preceding zeros in data frame)
Add leading zeros in Python pandas (preceding zeros in data frame) - DataScience Made Simple
October 17, 2024 - ## Add leading zeros to the integer column in Python df['Col2']=df['Col1'].apply(lambda x: '{0:0>10}'.format(x)) df ยท Col1 is replaced with leading zeros till the length of the field reaches to 10 digit ยท # create dataframe import pandas as pd d = {'Col1' : ["1","200","3000","40000"]} df=pd.DataFrame(d) df
Find elsewhere
๐ŸŒ
Skytowner
skytowner.com โ€บ explore โ€บ creating_a_dataframe_with_zeros_in_pandas
Creating a DataFrame with zeros in Pandas
To create a DataFrame with zeros in Pandas, pass in the value 0 to the DataFrame constructor and supply the parameters index and columns.
๐ŸŒ
Statology
statology.org โ€บ home โ€บ how to add leading zeros to strings in pandas
How to Add Leading Zeros to Strings in Pandas
March 3, 2022 - #add leading zeros to 'ID' column df['ID'] = df['ID'].apply('{:0>7}'.format) #view updated DataFrame print(df) ID sales refunds 0 0000A25 18 1 1 000B300 12 3 2 00000C6 27 3 3 D447289 30 2 4 000E416 45 5 5 0000F19 23 0 ยท Notice that leading zeros have been added to the strings in the โ€˜IDโ€™ column so that each string now has the same length. Note: You can find the complete documentation for the apply function in pandas here.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-add-empty-column-to-dataframe-in-pandas
How to add Empty Column to Dataframe in Pandas? - GeeksforGeeks
May 5, 2025 - Appending rows and columns to an empty DataFrame in pandas is useful when you want to incrementally add data to a table without predefining its structure.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas โ€“ add an empty column to a dataframe
Pandas - Add an Empty Column to a DataFrame - Spark By {Examples}
July 7, 2025 - There are multiple ways to add a new empty/blank column (single or multiple columns) to a pandas DataFrame by using assign operator, assign(), insert()
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ pandas โ€บ string โ€บ python-pandas-string-exercise-3.php
Pandas: Add leading zeros to the integer column in a pandas series and makes the length of the field to 8 digit - w3resource
Write a Pandas program to add leading zeros to the integer column in a pandas series and makes the length of the field to 8 digit. ... import pandas as pd nums = {'amount': [10, 250, 3000, 40000, 500000]} print("Original dataframe:") df = pd.DataFrame(nums) print(df) print("\nAdd leading zeros:") df['amount'] = df['amount'].apply(lambda x: '{0:0>8}'.format(x)) print(df)