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

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
BUG: Replacing NaN with None in Pandas 1.3 does not work
I have checked that this issue has not already been reported. I have confirmed this bug exists on the latest version of pandas. (optional) I have confirmed this bug exists on the master branch of p... More on github.com
🌐 github.com
10
July 7, 2021
BUG: dataframe.replace({np.nan: None}) failed when replaced even number of times
It should consistently have the ... no np.nan, doesn't matter how many replace attempts have been made. commit : 945c9ed python : 3.8.12.final.0 python-bits : 64 OS : Linux OS-release : 4.18.0-240.1.1.el8_3.x86_64 Version : #1 SMP Fri Oct 16 13:36:46 EDT 2020 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : None LOCALE : en_US.UTF-8 · pandas : 1.3.4 numpy ... More on github.com
🌐 github.com
6
November 16, 2021
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
🌐
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.
🌐
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
🌐
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)
🌐
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, '')
🌐
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 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 the common ways to represent the missing data value in Python/Pandas DataFrame.
Find elsewhere
🌐
GitHub
github.com › pandas-dev › pandas › issues › 42423
BUG: Replacing NaN with None in Pandas 1.3 does not work · Issue #42423 · pandas-dev/pandas
July 7, 2021 - >>> import pandas as pd >>> import numpy as np >>> df = pd.DataFrame([0.5, np.nan]) >>> df.where(pd.notnull(df), None) 0 0 0.5 1 NaN · Replacing NaN values with None (or any other Python object) should work as in previous Pandas versions. >>> import pandas as pd >>> import numpy as np >>> df = pd.DataFrame([0.5, np.nan]) >>> df.where(pd.notnull(df), None) 0 0 0.5 1 None ·
Author   pvieito
🌐
Medium
medium.com › @whyamit101 › pandas-nan-to-none-80a919f8fa67
pandas nan to none. The biggest lie in data science? That… | by why amit | Medium
April 12, 2025 - Can I convert None back to NaN? You absolutely can. You just need to do the reverse conversion using Pandas like this:
🌐
GitHub
github.com › pandas-dev › pandas › issues › 44485
BUG: dataframe.replace({np.nan: None}) failed when replaced even number of times · Issue #44485 · pandas-dev/pandas
November 16, 2021 - import numpy as np import pandas as pd def check_nan(df): for entry in df.to_dict(orient='records'): if any([isinstance(v, float) and np.isnan(v) for v in entry.values()]): return True return False def generate_df(): return pd.DataFrame(dict(age=[5, 6, np.NaN], born=[pd.NaT, pd.Timestamp('1939-05-27'), pd.Timestamp('1940-04-25')], name=['Alfred', 'Batman', ''], toy=[None, 'Batmobile', 'Joker'])) def where_not_working(): df = generate_df() df = df.where((pd.notnull(df)), None) print('where not working', check_nan(df)) def replace_working(): df = generate_df() df = df.replace({np.nan: None}) pri
Author   wchengit
🌐
Bobby Hadz
bobbyhadz.com › blog › replace-none-with-nan-in-pandas
How to replace None with NaN in Pandas DataFrame | bobbyhadz
April 11, 2024 - You can use the pandas.DataFrame.fillna() method to replace None with NaN in a pandas DataFrame.
🌐
Reddit
reddit.com › r/learnpython › how to fillna with none in a pandas dataframe?
r/learnpython on Reddit: How to fillna with None in a pandas dataframe?
May 2, 2018 -

Pretty straightforward, I have a dataframe that has columns with different mixtures of np.nan and None as the "null" value for that column. I want to get them all to be "None", but

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

all don't work. Anyone run into this issue before?

Also why the bloody fucking hell does

np.nan==np.nan

evaluate to false? (Yes I know its by definition, but some bloke thought it was a good idea to write the definition that way.) Is that actually useful for anything? In this particular case, it makes me want to use None instead.

🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
Missing values in pandas (nan, None, pd.NA) | note.nkmk.me
August 2, 2023 - If you want to treat certain values as missing, you can use the replace() method to replace them with float('nan'), np.nan, or math.nan. pandas: Replace values in DataFrame and Series with replace()
🌐
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 >>> Details · 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
Author   fsck-mount
🌐
GitHub
github.com › pandas-dev › pandas › issues › 29024
Inconsistent behavior for df.replace() with NaN, NaT and None · Issue #29024 · pandas-dev/pandas
October 16, 2019 - Replacing NaT with None (only) also replaces NaN with None. Replacing NaN with None also replaces NaT with None
Author   K3UL
🌐
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 ...
🌐
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