DataFrame.fillna() or Series.fillna() will do this for you.

Example:

In [7]: df
Out[7]: 
          0         1
0       NaN       NaN
1 -0.494375  0.570994
2       NaN       NaN
3  1.876360 -0.229738
4       NaN       NaN

In [8]: df.fillna(0)
Out[8]: 
          0         1
0  0.000000  0.000000
1 -0.494375  0.570994
2  0.000000  0.000000
3  1.876360 -0.229738
4  0.000000  0.000000

To fill the NaNs in only one column, select just that column.

In [12]: df[1] = df[1].fillna(0)

In [13]: df
Out[13]: 
          0         1
0       NaN  0.000000
1 -0.494375  0.570994
2       NaN  0.000000
3  1.876360 -0.229738
4       NaN  0.000000

Or you can use the built in column-specific functionality:

df = df.fillna({1: 0})
Answer from Aman on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › replace-nan-values-with-zeros-in-pandas-dataframe
Replace NaN Values with Zeros in Pandas DataFrame - GeeksforGeeks
Syntax to replace NaN values with zeros of a single column in Pandas dataframe using fillna() function is as follows: Syntax: df['DataFrame Column'] = df['DataFrame Column'].fillna(0)
Published   July 15, 2025
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.fillna.html
pandas.DataFrame.fillna — pandas 3.0.2 documentation
Replace all NaN elements in column ‘A, ‘B’, ‘C’, and ‘D’, with 0, 1, 2, and 3 respectively.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas replace nan values with zero in a column
Pandas Replace NaN Values with Zero in a Column - Spark By {Examples}
June 26, 2025 - You can use the pandas.DataFrame.fillna() or pandas.DataFrame.replace() methods to replace all NaN or None values in an entire DataFrame with zeros (0).
🌐
Statology
statology.org › home › how to replace nan values with zero in pandas
How to Replace NaN Values with Zero in Pandas
September 18, 2021 - #replace NaN values with zero in 'assists' column df['assists'] = df['assists'].fillna(0) #view updated DataFrame print(df) points assists rebounds 0 25.0 5.0 11.0 1 NaN 0.0 8.0 2 15.0 7.0 10.0 3 14.0 0.0 6.0 4 19.0 12.0 6.0 5 23.0 9.0 NaN 6 25.0 9.0 9.0 7 29.0 4.0 NaN
🌐
Medium
medium.com › @amit25173 › how-to-fill-nan-values-with-0-in-pandas-a665c5bf9967
How to Fill NaN Values with 0 in Pandas? | by Amit Yadav | Medium
March 6, 2025 - You don’t want your analysis to break just because of a few missing values, right? This is where fillna(0) comes in. It’s the easiest way to replace all NaN values with 0, ensuring your calculations stay accurate.
🌐
AskPython
askpython.com › home › how to replace nan values in a pandas dataframe with 0?
How to replace NaN values in a Pandas dataframe with 0? - AskPython
September 24, 2022 - In the above code, we applied the replace() function to replace NaN values with 0 in the ‘Rating’ column of the dataframe.
Find elsewhere
🌐
w3resource
w3resource.com › python-exercises › pandas › python-pandas-data-frame-exercise-32.php
Pandas: Replace all the NaN values with Zero's in a column of a dataframe - w3resource
September 5, 2025 - Some of the students have missing scores, which are represented as np.nan values. df = df.fillna(0): The fillna() method is then used to fill in these missing values with 0. Finally the resulting DataFrame is printed to the console using print() function. ... Write a Pandas program to replace NaN values with zeros in a specified column and then check data types remain unchanged.
🌐
Python Guides
pythonguides.com › pandas-replace-nan-with-0
How To Fill NaN Values With Zeros In Pandas DataFrames
May 21, 2025 - Read Fix “Function Not Implemented for This Dtype” Error in Python · The simplest and most direct way to replace NaN values with zeros is to use the fillna() method in Python: # Replace all NaN values with 0 merged_sales_filled = merged_sales.fillna(0) print(merged_sales_filled)
🌐
Statology
statology.org › home › pandas: how to replace zero with nan
Pandas: How to Replace Zero with NaN
October 3, 2022 - import numpy as np #replace all zeros with NaN values df.replace(0, np.nan, inplace=True) #view updated DataFrame print(df) points assists rebounds 0 25.0 5.0 11.0 1 NaN NaN 8.0 2 15.0 7.0 10.0 3 14.0 NaN 6.0 4 19.0 12.0 6.0 5 23.0 9.0 NaN 6 25.0 9.0 9.0 7 29.0 4.0 NaN · Notice that each zero in every column of the DataFrame has been replaced with NaN. Note: We must use the argument inplace=True or else the changes won’t be made to the original DataFrame. Related: How to Replace NaN Values with Zero in Pandas
🌐
Erikrood
erikrood.com › Python_References › replace_nan_zero_final.html
Replace all NaN values with 0's in a column of Pandas dataframe
import pandas as pd import numpy as np · raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'], 'age': [20, 19, 22, 21], 'favorite_color': ['blue', 'red', 'yellow', "green"], 'grade': [88, 92, 95, 70]} df = pd.DataFrame(raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel']) df · #First, we have to create the NaN values df = df.replace(20,np.NaN) df = df.replace(70,np.NaN) df ·
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pandas-dataframe-fillna-to-replace-null-values-in-dataframe
Pandas DataFrame.fillna() | Python - GeeksforGeeks
February 23, 2026 - DataFrame.fillna() is used to replace missing values (NaN) in a Pandas DataFrame with a specified value or using a filling method. It helps clean incomplete data so that analysis and calculations can be performed correctly.
🌐
Python Examples
pythonexamples.org › pandas-dataframe-replace-nan-values-with-zero
How to Replace NaN values with Zero in Pandas DataFrame?
Then we will use fillna() method to replace these numpy.nan values with zero. import pandas as pd import numpy as np df = pd.DataFrame( [[np.nan, 72, 67], [23, 78, 62], [32, 74, np.nan], [np.nan, 54, 76]], columns=['a', 'b', 'c']) print('Original DataFrame\n', df) df = df.fillna(0) ...
🌐
Arab Psychology
scales.arabpsychology.com › home › how to easily replace nan values with zero in pandas using fillna()
How To Easily Replace NaN Values With Zero In Pandas Using Fillna()
December 4, 2025 - The core function driving all these operations is fillna(). By setting the input parameter to 0, we instruct Pandas to replace all instances of NaN found within the specified selection with the integer or float representation of zero.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas replace blank values (empty) with nan
Pandas Replace Blank Values (Empty) with NaN - Spark By {Examples}
June 26, 2025 - In pandas, you can replace blank values (empty strings) with NaN using the replace() method. In this article, I will explain the replacing blank values or
🌐
TidyStat
35.199.173.34.bc.googleusercontent.com › home › how to replace nan with zero in pandas
How to Replace NaN with Zero in Pandas
January 20, 2025 - You can replace NaN with zero using either fillna(0) in Pandas or replace(np.nan,0) in Numpy. ... The following Python code first creates a dataframe with NaN in both columns and then replaces NaN in the first column with 0 using fillna(0).
🌐
Dataquest Community
community.dataquest.io › q&a › dq courses
Why should you replace a 0 with a NAN value? - DQ Courses - Dataquest Community
January 20, 2021 - Screen Link: My Code: import numpy as np prev_rank_before = f500["previous_rank"].value_counts(dropna=False).head() f500.loc[f500["previous_rank"] == 0, "previous_rank"] = np.nan prev_rank_after = f500["previous_rank"].value_counts(dropna=False).head() I have two questions about this assignment: Why should you replace a 0 value with a Nan?
🌐
Arab Psychology
scales.arabpsychology.com › home › how to easily replace nan values with strings in a pandas dataframe
How To Easily Replace NaN Values With Strings In A Pandas DataFrame
December 3, 2025 - Observation confirms that the NaN at index 0 of the ‘points’ column has been converted to ‘zero’. Significantly, the NaNs in ‘assists’ and ‘rebounds’ (at indices 1, 3, and 7) remain unchanged, demonstrating the surgical precision of applying the DataFrame.fillna() method to a single ...