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
🌐
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.
Discussions

python - Replace NaN in one column with value from corresponding row of second column - Stack Overflow
I am working with this Pandas DataFrame in Python. File heat Farheit Temp_Rating 1 YesQ 75 N/A 1 NoR 115 N/A 1 YesA 63 N/A 1 NoT 83 41 1 NoY 100 80 1 YesZ 56 12 2 YesQ 111 N/A 2 NoR 60 N/A 2 YesA 19 N/A 2 NoT 106 77 2 NoY 45 21 2 YesZ 40 54 3 YesQ 84 N/A 3 NoR 67 N/A 3 YesA 94 N/A 3 NoT 68 39 3 NoY 63 46 3 YesZ 34 81 · I need to replace all NaNs in the Temp_Rating column ... More on stackoverflow.com
🌐 stackoverflow.com
July 7, 2017
Help! Filling NaN with a certain values based on conditions from other column?
Hi all I am complete novice in coding 6 weeks in… I am working on large data set 18 columns with 1,282,354 entries for my assignment and I’m stuck on this issue: The dataset has two location columns “State” and “ZIP Code” see below sample. State ZIPCode 0 CA 4568 1 NaN NaN 2 FL ... More on discuss.python.org
🌐 discuss.python.org
0
0
October 6, 2022
python - What is the best solution to replace NaN values? - Data Science Stack Exchange
I'm thinking about using the normal distribution of a specific column that has missing values and replace them by random values generated using the normal distribution function of numpy on that spe... More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
February 27, 2021
I need to replace NaN in one column with value for other col
I've seen this come up before. You want to use np.where. data['Grade'] = np.where(data['Grade'].isna(),data['Score'],data['Grade']) here's an example that sets null values in grade to values in score, and if it's not null, leaves the current value. More on reddit.com
🌐 r/learnpython
10
1
July 15, 2021
🌐
Reddit
reddit.com › r/learnpython › i need to replace nan in one column with value for other col
r/learnpython on Reddit: I need to replace NaN in one column with value for other col
July 15, 2021 -

I've been working on learning Python and for something to code, I picked some VBA that I had.

In VBA:

     If Cells(I, "C").Value <> "" And Cells(I, "B").Value = "" Then
       Cells(I, "B").Value = Cells(I, "C").Value
     End If

It simply checks if colC is not Null and colB is Null, then replaces colB with the value from colC.

I can read in the csv file, I was able to select and delete some rows I didn't want, but I can't seem to get the syntax right for this...

🌐
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 - Sometimes you may need to update NaN values with zeros on single or multiple columns of DataFrame, let’s apply the fillna() function on the specified column of DataFrame to replace all NaN values of that particular column with zeros.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.2 documentation
For example, {'a': 1, 'b': 'z'} looks for the value 1 in column ‘a’ and the value ‘z’ in column ‘b’ and replaces these values with whatever is specified in value. The value parameter should not be None in this case. You can treat this as a special case of passing two lists except that you are specifying the column to search in. For a DataFrame nested dictionaries, e.g., {'a': {'b': np.nan}}, are read as follows: look in column ‘a’ for the value ‘b’ and replace it with NaN.
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Replace NaN (missing values) with fillna() | note.nkmk.me
February 1, 2024 - In pandas, the fillna() method allows you to replace NaN values in a DataFrame or Series with a specific value.
Find elsewhere
🌐
Statology
statology.org › home › pandas: how to fill nan values with values from another column
Pandas: How to Fill NaN Values with Values from Another Column
June 1, 2022 - We can use the fillna() function to fill the NaN values in the team1 column with the corresponding value in the team2 column:
🌐
Skytowner
skytowner.com › explore › replacing_values_with_nans_in_pandas_dataframe
Replacing values with NaNs in Pandas DataFrame
To replace values with NaN, use the DataFrame's replace(~) method. ... Note that the replacement is not done in-place, that is, a new DataFrame is returned and the original df is kept intact. To perform the replacement in-place, set inplace=True. ... Replaces the specified values with another ...
🌐
Statology
statology.org › home › pandas: how to replace nan values with string
Pandas: How to Replace NaN Values with String
November 1, 2021 - Notice that the NaN value in the ‘points’ column was replaced replaced with the string ‘zero’, but the NaN values in the ‘assists’ and ‘rebounds’ columns remained unchanged. The following tutorials explain how to perform other common operations in pandas:
🌐
Moonbooks
moonbooks.org › Articles › How-to-replace-NaN-values-in-a-pandas-dataframe-
How to replace NaN values in a pandas dataframe ?
August 25, 2022 - How to replace NaN values with zeros in a column of a pandas DataFrame in Python · Pandas replace nan depending on type · This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Author · Developer in my spare time, I’m interested in Earth observation and satellite-based fire detection.
🌐
GeeksforGeeks
geeksforgeeks.org › replace-nan-values-with-zeros-in-pandas-dataframe
Replace NaN Values with Zeros in Pandas DataFrame - GeeksforGeeks
The dataframe.replace() function in Pandas can be defined as a simple method used to replace a string, regex, list, dictionary, etc. in a DataFrame. Replace NaN values with zeros for a column using NumPy replace()
Published   August 12, 2024
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas replace nan with blank/empty string
Pandas Replace NaN with Blank/Empty String - Spark By {Examples}
November 19, 2024 - The inplace=True parameter in fillna() allows modifying the DataFrame without creating a new copy. Replace NaN with a blank string in specific columns by selecting them before applying fillna().
🌐
Python.org
discuss.python.org › python help
Help! Filling NaN with a certain values based on conditions from other column? - Python Help - Discussions on Python.org
October 6, 2022 - Hi all I am complete novice in coding 6 weeks in… I am working on large data set 18 columns with 1,282,354 entries for my assignment and I’m stuck on this issue: The dataset has two location columns “State” and “ZIP Code” see below sample. State ZIPCode 0 CA 4568 1 NaN NaN 2 FL 4546XX 3 TX 323 4 NY 45578 5 NaN 7857x 6 GA 7888AC 7 AA NaN I have some missing values and wanted to replace them based on the value of one of the columns for example: ...
🌐
AskPython
askpython.com › home › how to replace nan values in pandas with an empty string?
How to Replace NAN Values in Pandas with an Empty String? - AskPython
March 29, 2022 - This method is used to replace all NAN values in a DataFrame with an empty string. df2 = df.replace(np.nan, '', regex=True) print(df2) ... In this method, we will only replace the NAN values in the columns that are specified.
🌐
Pandas
pandas.pydata.org › docs › user_guide › missing_data.html
Working with missing data — pandas documentation - PyData |
In [98]: data = {"np": [1.0, np.nan, np.nan, 2], "arrow": pd.array([1.0, pd.NA, pd.NA, 2], dtype="float64[pyarrow]")} In [99]: df = pd.DataFrame(data) In [100]: df Out[100]: np arrow 0 1.0 1.0 1 NaN <NA> 2 NaN <NA> 3 2.0 2.0 In [101]: df.fillna(None) Out[101]: np arrow 0 1.0 1.0 1 NaN <NA> 2 NaN <NA> 3 2.0 2.0 In [102]: df.fillna(np.nan) Out[102]: np arrow 0 1.0 1.0 1 NaN <NA> 2 NaN <NA> 3 2.0 2.0 In [103]: df.fillna(pd.NA) Out[103]: np arrow 0 1.0 1.0 1 NaN <NA> 2 NaN <NA> 3 2.0 2.0 ... In [104]: df.ffill() Out[104]: np arrow 0 1.0 1.0 1 1.0 1.0 2 1.0 1.0 3 2.0 2.0 In [105]: df.bfill() Out[105]: np arrow 0 1.0 1.0 1 2.0 2.0 2 2.0 2.0 3 2.0 2.0 ... NA values can be replaced with corresponding value from a Series or DataFrame where the index and column aligns between the original object and the filled object.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-replace-a-string-value-with-nan-in-pandas-data-frame-python
How to Replace a String Value with NaN in Pandas Data Frame Python | Saturn Cloud Blog
November 14, 2023 - In this article, we will discuss how to replace a string value with NaN in Pandas data frame using Python. Pandas is a popular data manipulation library for Python. It provides powerful tools for data cleaning, preprocessing, and analysis. Pandas data frames are two-dimensional labeled data structures with columns ...