[SciPy-User] Question about scikits.timeseries.lib.moving_funcs.mov_average

Pierre GM pgmdevlist@gmail....
Wed Jun 23 13:35:35 CDT 2010

On Jun 23, 2010, at 11:45 AM, Andreas wrote:

> Thanks a lot for your input!
>> You could try to fill your missing values beforehand, w/ functions like
>> backward_fill and forward_fill, then passing your series to mov_average.
> Well, that's not really what I want. By doing what you suggest, I make the
> assumption that the value actually changed on the day for which I have the
> measurement. But each measurement is only one single point in time, so I
> do not want to make this assumption.

Ah OK. Makes sense.

> Basically, I'm looking for a simple and efficient way to do something like
> this::
>   w = 11 # the window size
>   s = (w-1)*.5
>   for d in data.dates:
>     newdata[d] = data[d-s:d+s+1].mean()

Ah OK. Note that you should use cmov_mean, then...
Well, several possibilities:

* Make sure you don't have missing dates (use fill_missing_dates), then construct a list of slices and apply .mean() on the .series (so that you don't use __getitem__ on the whole series, only on the masked data part, saves some time).

* Use some tricks:
- the moving_funcs functions don't need timeseries as inputs, masked arrays are just fine
- compute cmov_mean on the data part (filled w/ 0)
- compute cmov_mean on the opposite of the mask (viz, np.logical_not(x.mask)
- divide the first by the second.

More information about the SciPy-User mailing list