[SciPy-User] iterating in a timeseries

Dave Hirschfeld dave.hirschfeld at gmail.com
Wed Nov 4 08:49:27 EST 2009


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?

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




More information about the SciPy-User mailing list