Is there any difference between np.Nan and np.nan? As per my understanding both are used for null values but if you look here
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame([[np.nan,2,np.nan,0],[3,4,np.nan,1],[np.nan,np.nan,np.nan,5]],columns=list('ABCD'))
print(df)
print(np.nan == np.NaN)
I get following output:
A B C D
0 NaN 2.0 NaN 0
1 3.0 4.0 NaN 1
2 NaN NaN NaN 5
False
Process finished with exit code 0
Now if these are same print(np.nan == np.NaN)
should return True
and why are the values in dataframe populated as NaN
?
I get NaN
is not a number so it might be treating it that way and hence changing the entry in dataframe but I am still not sure.
nan
s, it will always return False. i.e.np.nan == np.nan
is alsoFalse
. But testing identity withis
,np.nan is np.NaN
isTrue
. See IEEE 754 Floating Point Special Values in the NumPy docs. – Dorrisboth are used for null values
- no. Not null. "Not a number". – MilkwhiteNaN ≠ NaN
holds in any IEEE 754 compliant floating-point system. So you will find this behaviour almost anywhere you look, not just in Python. This goes all the way down to the CPU level. en.wikipedia.org/wiki/NaN – Uncovenanted