[SciPy-User] scikits.timeseries: Using dtype in tsfromtxt

all6junk@gmai... all6junk@gmai...
Tue Oct 20 18:44:44 CDT 2009

Hi all,

I am new to using numpy and scikits.timeseries. I am facing small  
difficulty in loading time series data from a text file which has data like

20051017, 380.00, 386.30
20051018, 386.85, 388.55
20051019, 371.60, 373.55
20051020, 365.30, 371.85
20051021, 360.35, 368.50
20051024, 368.50, 379.90

I use the following code to read in the timeseries data
import numpy.ma as ma
import datetime
import scikits.timeseries as ts
import matplotlib.pyplot as plt
import scikits.timeseries.lib.plotlib as tpl

def dconv(s):
     s = str(s)
     yyyy = int(s[:4])
     mm = int(s[4:6])
     dd = int(s[6:8])

     return ts.Date('B', year=yyyy, month=mm, day=dd)

def loadscrip(scripfile):
     dt = np.dtype([('date', 'a8'), ('open', 'f4'), ('high', 'f4')])
     ser = ts.tsfromtxt(scripfile, dtype=dt,
             delimiter=',', datecols=(0), dateconverter=dconv)
     return ser

if __name__ == '__main__':
     scripfile = 'test_data.csv'
     scripdata = loadscrip(scripfile)

I get the following error,
Traceback (most recent call last):
   File "tsfromtxt.py", line 24, in <module>
     scripdata = loadscrip(scripfile)
   File "tsfromtxt.py", line 19, in loadscrip
     delimiter=',', datecols=(0), dateconverter=dconv)
line 432, in tsfromtxt
     mrec = genfromtxt(fname, **kwargs)
line 920, in genfromtxt
     converters[i].update(conv, default=None,
IndexError: list index out of range

I know I am doing some silly error. But probably someone can save me from  
pulling my hair out.


More information about the SciPy-User mailing list