df = df.replace({np.nan: None})

Note: For pandas versions <1.4, this changes the dtype of all affected columns to object.
To avoid that, use this syntax instead:

df = df.replace(np.nan, None)

Note 2: If you don't want to import numpy, np.nan can be replaced with native float('nan'):

df = df.replace({float('nan'): None})

Credit goes to this guy here on this Github issue, Killian Huyghe's comment and Matt's answer.

Answer from EliadL on Stack Overflow
🌐
Statology
statology.org › home › pandas: how to replace nan with none
Pandas: How to Replace NaN with None
December 1, 2022 - This tutorial explains how to replace NaN values with a None value in a pandas DataFrame, including an example.
Discussions

Replace None with NaN in pandas dataframe - Stack Overflow
Just double-checked it, it does work for me. Do you get any errors or the 'None' values don't get replaced? 2018-04-30T00:35:08.817Z+00:00 ... NB: this method uses np.nan, which has a float dtype (e.g.: float64), as opposed to pandas's default dtype of object for a nan column. More on stackoverflow.com
🌐 stackoverflow.com
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
in consistent result with replace(np.nan, None, inplace=True)
Expected it to fill 'nan' with None. But, it will some of the columns with the value from columns where it is not nan. More on github.com
🌐 github.com
8
September 11, 2017
python - Pandas Replace NaN with blank/empty string - Stack Overflow
I have a Pandas Dataframe as shown below: 1 2 3 0 a NaN read 1 b l unread 2 c NaN read I want to remove the NaN values with an empty string so that it looks like so:... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.fillna.html
pandas.DataFrame.fillna — pandas 3.0.2 documentation
For non-object dtype, value=None will use the NA value of the dtype. See more details in the Filling missing data section. ... >>> df = pd.DataFrame( ... [ ... [np.nan, 2, np.nan, 0], ... [3, 4, np.nan, 1], ... [np.nan, np.nan, np.nan, np.nan], ... [np.nan, 3, np.nan, 4], ... ], ... columns=list("ABCD"), ... ) >>> df A B C D 0 NaN 2.0 NaN 0.0 1 3.0 4.0 NaN 1.0 2 NaN NaN NaN NaN 3 NaN 3.0 NaN 4.0 · Replace all NaN elements with 0s.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-replace-none-with-nan-in-pandas-dataframe
How to Replace None with NaN in Pandas DataFrame | Saturn Cloud Blog
January 16, 2024 - In this blog, if you find yourself in the role of a data scientist or software engineer, you might encounter a scenario necessitating the replacement of None values with NaN in a Pandas DataFrame. This task is routine when dealing with data, as NaN values are commonly employed in Pandas to ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › replacing-pandas-or-numpy-nan-with-a-none-to-use-with-mysqldb
Replacing Pandas or Numpy Nan with a None to use with MysqlDB - GeeksforGeeks
July 23, 2025 - The resulting DataFrame 'replaced_df' contains 'None' in place of 'NaN' values. ... import pandas as pd import numpy as np df = pd.DataFrame({'A': [1, np.nan,3], 'B': [np.nan, 5, 6], 'C': [7, 8, np.nan]}) replaced_df = df.replace({np.nan: None}) print(replaced_df)
🌐
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...

Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › replace-none-with-nan-in-pandas
How to replace None with NaN in Pandas DataFrame | bobbyhadz
April 11, 2024 - The Name and Age columns contain both "None" strings and None values. We set the to_replace argument to a list containing both values to be able to replace both with NaN. You can also do this for a specific column only.
🌐
IARP
iarp.github.io › python › pandas-replace-nan-nat-with-none.html
Pandas replace all NaN and NaT values with None | IARP
View On GitHub · GitHub Profile · Pandas replace all NaN and NaT values with None · data.replace({pandas.NaT: None}, inplace=True) · Hosted on GitHub Pages using the Dinky theme
🌐
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 - By using replace() or fillna() methods you can replace NaN values with Blank/Empty string in Pandas DataFrame. NaN stands for Not A Nuber and is one of
🌐
Arab Psychology
scales.arabpsychology.com › home › how to easily replace nan with none in your pandas dataframe
How To Easily Replace NaN With None In Your Pandas DataFrame
November 22, 2025 - To restrict the replacement operation to one or more specific columns, we apply the replace() method directly to the selected Pandas Series (column). This maintains the integrity and efficiency of the remaining columns.
🌐
JanBask Training
janbasktraining.com › community › data-science › pandas-replace-nan-with-none
Replace None with NaN in pandas dataframe | JanBask Training Community
July 8, 2021 - I have table x: website0 http://www.google.com/1 http://www.yahoo.com2 NoneI want to replace python None with pandas NaN. I tried:x.replace(to_rep
🌐
GeeksforGeeks
geeksforgeeks.org › python › replace-nan-with-blank-or-empty-string-in-pandas
Replace NaN with Blank or Empty String in Pandas? - GeeksforGeeks
July 23, 2025 - This function will replace an empty string inplace of the NaN value. ... # import pandas module import pandas as pd # import numpy module import numpy as np # create dataframe with 3 columns data = pd.DataFrame({ "name": ['sravan', np.nan, 'harsha', 'ramya'], "subjects": [np.nan, 'java', np.nan, 'html/php'], "marks": [98, np.nan, np.nan, np.nan] }) # replace nan with empty string # using replace() function data.replace(np.nan, '')
🌐
GitHub
github.com › pandas-dev › pandas › issues › 17494
in consistent result with replace(np.nan, None, inplace=True) · Issue #17494 · pandas-dev/pandas
September 11, 2017 - >>> data = [ ... {'hello': 1, 'mad': 2, 'world': 3}, ... {'mad': 2, 'world': 3}, ... {'world': 1} ... ] >>> df = pd.DataFrame(data) >>> df hello mad world 0 1.0 2.0 3 1 NaN 2.0 3 2 NaN NaN 1 >>> df.hello.dropna() 0 1.0 Name: hello, dtype: float64 >>> import numpy as np >>> df.hello.replace(np.nan, None, inplace=True) >>> df.hello 0 1.0 1 1.0 2 1.0 Name: hello, dtype: float64 >>> ... commit: None python: 2.7.12.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-1032-aws machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: None.None · pandas: 0.20.3 pytest
Author   fsck-mount
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.2 documentation
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
Missing values in pandas (nan, None, pd.NA) | note.nkmk.me
August 2, 2023 - Unlike None, inf in the object column is also converted to nan. pd.options.mode.use_inf_as_na = True print(s_inf) # 0 NaN # 1 NaN # dtype: float64 print(s_inf.isnull()) # 0 True # 1 True # dtype: bool s_inf_object = pd.Series([float('inf'), -float('inf'), 'abc']) print(s_inf_object) # 0 NaN # 1 NaN # 2 abc # dtype: object print(s_inf_object.isnull()) # 0 True # 1 True # 2 False # dtype: bool ... See the following article on how to set options 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 ·
🌐
Arab Psychology
scales.arabpsychology.com › stats › how-can-i-replace-nan-values-with-none-in-pandas
How Can I Replace NaN Values With None In Pandas?
June 25, 2024 - This can be achieved in Pandas by using the .fillna() method and specifying the value to be replaced as None. This allows for easier handling of missing values in data analysis tasks.