[SciPy-User] How do I add a data point into scikits.timeseries

Pierre GM pgmdevlist at gmail.com
Fri Jul 31 16:49:33 EDT 2009


On Jul 31, 2009, at 2:55 PM, Leon Sit wrote:

> Hi everyone:
>
> I am trying to append a tuple of data, (datetime, data), into a  
> scikits.timeserieses. I do not know the size in advance so it must  
> be appended. Is there a way to do it efficiently as this will be a  
> primary operation that in done in order of million times.


Just like with standard arrays, appending to a TimeSeries is not very  
efficient. Instead, you may want to consider creating a list of tuples  
and appending as it goes. Then, create a TimeSeries out of it at the  
very end.

 >>>  test=[(dt.datetime(2009,01,d),f) for (d,f) in  
zip(range(1,16),np.random.rand(15))]
 >>> # Make a tmp array
 >>>  tmp=np.array(test,dtype=[('dates',object),('f',float)])
 >>> ts.time_series(tmp['f'],dates=tmp['dates'])

Note that you'd have to define a frequency or you'd end up with an  
'undefined' frequency...





More information about the SciPy-User mailing list