pythonscipystatisticsmissing-datageometric-mean

Scipy gmean with missing values


I was not sure how to deal with a two dimensional array [stock returns] that has some missing values.

I want to get geometric mean for each row [ average return for each month]. I got missing values for geometric mean for those months that I have missing values.

One way is to filling the missing values with something like 1 or mean but I don't want to mess with the mean.

Any advice how to calculate the gmean for each date just based on the not-missing values?

enter image description here

enter image description here


Solution

  • You should go with numpy.nanmean()

    https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.nanmean.html