Time for action – handling NaNs with the nanmean(), nanvar(), and nanstd() functions
We will apply jackknife resampling to the stock data. Each value will be omitted by setting it to Not a Number (NaN). The nanmean()
, nanvar()
, and nanstd()
can then be used to compute the arithmetic mean, variance, and standard deviation.
- First, initialize a 30-by-3 array for the estimates as follows:
estimates = np.zeros((len(c), 3))
- Loop through the values and generate a new dataset by setting one value to NaN at each iteration of the loop. For each new set of values, compute the estimates:
for i in xrange(len(c)): a = c.copy() a[i] = np.nan estimates[i,] = [np.nanmean(a), np.nanvar(a), np.nanstd(a)]
- Print the variance for each estimate (you can also print the mean ...
Get NumPy : Beginner's Guide - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.