iterating in a timeseries

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

iterating in a timeseries

Zunbeltz Izaola-3
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

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: iterating in a timeseries

dhirschfeld
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

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: iterating in a timeseries

Zunbeltz Izaola-3
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
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/scipy-user

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user