Introduction:
Normally we check a lot of times whether some value is equal to something or not. Now, you may need to check the same with a nan, NaN, NAN value too. But the problem arises when you observe that a simple check nan == nan fails.
Why does the check fails:
The reason nan == nan sort of checks fail is because nan does not equate to anything, even itself. That's why, equating it ends up giving false.
Solution:
So, after going through stackoverflow, I found that the trustable solution which works for me as well, is np.isnan() function. There is a pd.isna() too for this same purpose. But for this example, I have used np.isnan() function only. Please observe the use of isnan below:
Observe how all the forms such as nan, NaN, NAN are getting detected by np.isnan().
Comments
Post a Comment