import numpy as np
mynan = np.nan
mynum = 18
print("NaN? : ", np.isnan(mynan)) # Use np.isnan() to test
print("NaN? : ", np.isnan(mynum))
# Results:
# Nan? : True
# NaN? : False
import math
x = float('nan')
math.isnan(x)
True
>>> import math
>>> x = float('nan')
>>> math.isnan(x)
True
math.isnan(n)
# Test to see if it is equal to itself
def isNaN(num):
return num != num
import numpy as np
import pandas as pd
val = np.nan
print(pd.isnull(val))
# True
Number.isNaN(123)
>>> pd.isnull(None)
True
import math
print math.isnan(float('NaN'))OutputTrue
print math.isnan(1.0)OutputFalse
import pandas as pd
import numpy as np
df = pd.DataFrame(
[[np.nan, 72, 67],
[23, 78, 62],
[32, 74, np.nan],
[np.nan, 54, 76]],
columns=['a', 'b', 'c'])
value = df.at[0, 'a'] #nan
isNaN = np.isnan(value)
print("Is value at df[0, 'a'] NaN :", isNaN)
value = df.at[0, 'b'] #72
isNaN = np.isnan(value)
print("Is value at df[0, 'b'] NaN :", isNaN)
import pandas as pd
pd.isnull(df.columnName).sum()
pd.notnull(df.columnName).sum()
# If you are doing any conditional operation and you want to check a if
# a single value is Null or not then you can use numpy's isna method.
np.isna(df[col][0])
if(term != term):
print("it's a nan value")