Python 3.1
I am doing some calculations on data that has no values. Any calculations that include a missing value should result in a missing value.
I think use float('nan')to represent missing values. It is safe? In the end, I just check
def is_missing(x):
return x!=x
It seems perfect, but I could not find a clear confirmation in the documentation.
I could use “No,” of course, but that would require me to do each calculation with try/ except TypeErrorto detect it. I could also use Inf, but I'm even less sure about how this works.
EDIT:
@MSN I understand that using NaN is slow. But if my choice is:
def f(a, b, c):
return a + b * c
or
def f(a, b, c):
if a is None or b is None or c is None:
return None
else:
return a + b * c
, NaN , ?