Checking if a double (or float) is NaN in C++

According to the IEEE standard, NaN values have the odd property that comparisons involving them are always false. That is, for a float f, f != f will be true only if f is NaN. Note that, as some comments below have pointed out, not all compilers respect this when optimizing code. For any compiler … Read more

What is the difference between size and count in pandas?

size includes NaN values, count does not: In [46]: df = pd.DataFrame({‘a’:[0,0,1,2,2,2], ‘b’:[1,2,3,4,np.NaN,4], ‘c’:np.random.randn(6)}) df Out[46]: a b c 0 0 1 1.067627 1 0 2 0.554691 2 1 3 0.458084 3 2 4 0.426635 4 2 NaN -2.238091 5 2 4 1.256943 In [48]: print(df.groupby([‘a’])[‘b’].count()) print(df.groupby([‘a’])[‘b’].size()) a 0 2 1 1 2 2 Name: … Read more

Set value for particular cell in pandas DataFrame using index

RukTech’s answer, df.set_value(‘C’, ‘x’, 10), is far and away faster than the options I’ve suggested below. However, it has been slated for deprecation. Going forward, the recommended method is .iat/.at. Why df.xs(‘C’)[‘x’]=10 does not work: df.xs(‘C’) by default, returns a new dataframe with a copy of the data, so df.xs(‘C’)[‘x’]=10 modifies this new dataframe only. … Read more

What is the rationale for all comparisons returning false for IEEE754 NaN values?

I was a member of the IEEE-754 committee, I’ll try to help clarify things a bit. First off, floating-point numbers are not real numbers, and floating-point arithmetic does not satisfy the axioms of real arithmetic. Trichotomy is not the only property of real arithmetic that does not hold for floats, nor even the most important. … Read more