Convert pandas.Series from dtype object to float, and errors to nans

Use pd.to_numeric with errors=”coerce” # Setup s = pd.Series([‘1’, ‘2’, ‘3’, ‘4’, ‘.’]) s 0 1 1 2 2 3 3 4 4 . dtype: object pd.to_numeric(s, errors=”coerce”) 0 1.0 1 2.0 2 3.0 3 4.0 4 NaN dtype: float64 If you need the NaNs filled in, use Series.fillna. pd.to_numeric(s, errors=”coerce”).fillna(0, downcast=”infer”) 0 1 1 … Read more

Why are floating point infinities, unlike NaNs, equal?

Your reasoning is that Double.POSITIVE_INFINITY should not be equal to itself because it is “likely” to have been obtained as the result of a loss of accuracy. This line of reasoning applies to all of floating-point. Any finite value can be obtained as the result of an inaccurate operation. That did not push the IEEE … Read more

Break on NaN in JavaScript

To answer the question as asked: Is there any modern browser that raises exceptions on NaN propagation (ie multiplying or adding a number to NaN), or that can be configured to do so? No. Javascript is a very forgiving language and doesn’t care if you want to multiply Math.PI by ‘potato’ (hint: it’s NaN). It’s … Read more

How do you test for NaN in JavaScript?

Short Answer For ECMAScript-5 Users: #1 if(x !== x) { console.info(‘x is NaN.’); } else { console.info(‘x is NOT a NaN.’); } For people using ECMAScript-6: #2 Number.isNaN(x); And For consistency purpose across ECMAScript 5 & 6 both, you can also use this polyfill for Number.isNan #3 //Polyfill from MDN Number.isNaN = Number.isNaN || function(value) … Read more

numpy array: replace nan values with average of columns

No loops required: print(a) [[ 0.93230948 nan 0.47773439 0.76998063] [ 0.94460779 0.87882456 0.79615838 0.56282885] [ 0.94272934 0.48615268 0.06196785 nan] [ 0.64940216 0.74414127 nan nan]] #Obtain mean of columns as you need, nanmean is convenient. col_mean = np.nanmean(a, axis=0) print(col_mean) [ 0.86726219 0.7030395 0.44528687 0.66640474] #Find indices that you need to replace inds = np.where(np.isnan(a)) #Place … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)