[SciPy-User] iterating in a timeseries

Zunbeltz Izaola zunbeltz@gmail....
Thu Nov 5 02:45:32 CST 2009


On Wed, 2009-11-04 at 13:49 +0000, Dave Hirschfeld wrote:
> Zunbeltz Izaola <zunbeltz <at> gmail.com> writes:
> 
> > 
> > Hi,
> > 
> > I am using scikits.timeseries. 
> > 
> > I have a time series with daily frequency, with data of 2 years.  I have
> > data almost every day, but some days are missing.
> > 
> > I want to iterate over the timeseries to get the values of the first and
> > last day of each month. I had tried to convert freq to 'M' and other
> > things, but I can not find an easy way. Any idea?
> > 
> > TIA,
> > 
> > Zunbeltz
> > 
> 
> 
> Does this do what you're looking for?
> 

Thanks, It works perfectly,

Zunbeltz

> from numpy.random import randint
> import scikits.timeseries as ts
> dates = ts.date_array(ts.Date('D','01-Jan-2009'),ts.Date('D','31-Dec-2011'))
> series = ts.time_series(dates.day,dates)
> monthly_series = series.convert('M')
> ts.first_unmasked_val(monthly_series,axis=1)
> ts.last_unmasked_val(monthly_series,axis=1)
> 
> # Example with missing data
> series[randint(0,series.size,512)] = ma.masked
> monthly_series = series.convert('M')
> ts.first_unmasked_val(monthly_series,axis=1)
> ts.last_unmasked_val(monthly_series,axis=1)
> 
> HTH,
> Dave
> 
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-User mailing list