Skip to content Skip to sidebar Skip to footer

Python None == None Is True Or False?

Is the condition None == None is true or false? I have 2 pandas-dataframes: import pandas as pd df1 = pd.DataFrame({'id':[1,2,3,4,5], 'value':[None,20,None,40,50]}) df2 = pd.DataF

Solution 1:

Pandas uses the floating point Not a Number value, NaN, to indicate that something is missing in a series of numbers. That's because that's easier to handle in the internal representation of data. You don't have any None objects in your series. Even so, if you use dtype=object data, None is used to encode missing value. See Working with missing data.

Not that it matters here, but NaN is always, by definition, not equal to NaN:

>>> float('NaN') == float('NaN')
False

When merging or broadcasting, Pandas knows what 'missing' means, there is no equality test being done on the NaN or None values in a series. Nulls are skipped explicitly.

If you want to test if a value is a null or not, use the series.isnull()and series.notnull() methods instead.

Post a Comment for "Python None == None Is True Or False?"