In the following examples, I create four types of 'nan' in Python. df
in a
is a data frame I loaded from a .txt file where one missing values sit on [2,2].
a = df.iloc[2,2]
b = pd.NA
c = np.nan
d = float('nan')
First, I had a look at these four values:
a
Out[122]: nan
b
Out[123]: <NA>
c
Out[124]: nan
d
Out[125]: nan
It looks like a,c and d are equal nan
values, And I decided to check their type:
type(a)
Out[116]: numpy.float64
type(b)
Out[117]: pandas._libs.missing.NAType
type(c)
Out[118]: float
type(d)
Out[119]: float
I want to check if they are equal in a sense:
c == d
Out[120]: False
a == d
Out[121]: False
a == c
Out[126]: False
My question is:
[1] Why c and d are not equal?
[2] Is there a way to convert float('nan') to np.nan?
[3] Is there a way to convert a
to np.nan?
Many thanks!