[SciPy-user] scikits.timeseries DateArray Question

Pierre GM pgmdevlist@gmail....
Wed Dec 3 11:49:22 CST 2008


Dharhas,
The documentation is a bit scarce indeed, and some functions are being  
rewritten (eg, loadtxt). For now, here's what you can do:

*First, load your data into an array with np.loadtxt,  
matplotlib.mlab.csv2rec, whatever.
 >>> loaded = np.loadtxt(...)

As in your example, we'll assume that the array in 6 cols wide, the  
first five being year, month, day, hour and min and the last one some  
data. No missing values in any of the first 5 cols, or find a way to  
fill them. Because your data are every 15 min or so, we need to use a  
'minute' frequency (code 'T' or 'MIN'). There might be gaps in dates,  
that's OK as long as the whole line is missing. For now, let's use

 >>> loaded = [(2008, 1, 1, 12, 0, 1.0), (2008, 1, 1, 12, 15, 2.0),  
(2008, 1, 1, 18, 0, 3.0)]

* Then, construct a DateArray from those first 5 cols. The simplest is  
to rely on datetime for that:
 >>> import scikits.timeseries as ts
 >>> import datetime
 >>> dates = ts.date_array([datetime.datetime(yy,mm,dd,hh,nn) for  
(yy,mm,dd,hh,nn,_) in loaded], freq='MIN')

* Now, construct your time series
 >>> series = ts.time_series([_[-1] for _ in loaded, dates=dates)


Let me know how it goes.
P.


On Dec 3, 2008, at 12:16 PM, Dharhas Pothina wrote:

> Hi,
>
> Thanks to Pierre's suggestion of using virtualenv package, I now  
> have a working install of the scikit.timeseries package installed. I  
> have some questions about constructing a timeseries from data in a  
> file. From the file I am reading Year,Month,Day,Hour,Min,Data and I  
> need to convert them to a timeseries. I've been looking through the  
> documentation and the mailing list archive and I'm not sure how to  
> create a DateArray that contains a non uniform list of datetimes.  
> The data is mostly at a 15 minute frequency but sometimes may not  
> fall exactly at 00,15,30,45 mins etc and other times may not be  
> present. All the examples I've seen involve data that is present in  
> a fixed frequency.
>
> ie.
>
> #Year Month Day Hour Min Data
> 2008 01 01 10 00 2.9
> 2008 01 01 10 15 3.2
> 2008 01 01 10 33 3.1
> 2008 01 01 12 45 3.0
> 2008 01 02 11 15 3.4
> ...
>
> Is there a way to read these dates into a DateArray so I can create  
> a timeseries?
>
> thanks,
>
> - dharhas
>
>
>
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list