[SciPy-User] ValueError with ts.convert of scikits.timeseries
Wed Mar 3 19:23:47 CST 2010
On Mar 3, 2010, at 5:47 PM, Marco Tuckner wrote:
> I encountered an error working with a recarray read from a ASCII file
> with ts.tsfromtxt .
> The steps were conducted:
> 1) read in with ts.tsfromtxt ==> recarray with data with minutely frequency
> 2) missing dates were filed with ts.fill_missing_dates ==> complete series
> 3) convert into hourly frequency with ts.convert
> 4) an error occurs, see below.
> What could be the cause for this?
The fact that you're using a structured array (that is, an array with named fields. a recarray is a special kind of structured array). The conversion functions don't work in that case, you have to convert field by field.
In your case, I'd do something like this:
* convert the first field to hours using .convert and save the reslut in a temporary array
* create an empty timeseries with the same dtype as your input and the same dates as the temporary array you just created.
* Loop on the fields of the input, convert them to hours and store them in the corresponding field of your new array
> My recarray have the following dtypes:
> dtype = [('f2', '<i4'), ('f3', '<f8'), ('f4', '<f8'), ('f5', '<i4'),
> ('f6', '<i4'), ('f7', '<f8'), ('f8', '<f8'), ('f9', '<f8'), ('f10',
> '<f8'), ('f11', '<f8'), ('f12', '<f8')],
> Another question related to this:
> How do I convert the recarrays returned by ts.tsfromtxt into a ndarray?
Use .view(np.ndarray). Note that on top of dropping the dates, you also lose the mask. If you need the mask, use the .series attribute.
More information about the SciPy-User