[SciPy-user] scikits.timeseries : Problem using tsfromtxt with converter

Dharhas Pothina Dharhas.Pothina@twdb.state.tx...
Thu Jul 16 08:08:07 CDT 2009


  I have data in the following format:

Date, 28.898 -95.334
09/01/2008 00:00, 0mm
09/01/2008 01:00, 0mm
09/01/2008 02:00, 0mm

If I read it using 

data = ts.tsfromtxt(file,skiprows=1,datecols=(0),delimiter=',',freq = 'H')

It reads in correctly but the data is read in as strings with the 'mm'. ie
 [[ 0mm]
 [ 0mm]
 [ 0mm]],
    dates =
 [01-Sep-2008 00:00 ... 01-Jun-2009 23:00],
    freq  = H)

I want to remove the 'mm' and read the data as floats. I tried using a converter:

conv = {1: lambda s: s.split('m')[0]}
data = ts.tsfromtxt(file,skiprows=1,datecols=(0),delimiter=',',freq = 'H',converters=conv)

but then I get an error which seems to have something to do with the date converter that was working in the earlier command:

/usr/lib64/python2.5/site-packages/scikits.timeseries-0.91.1-py2.5-linux-x86_64.egg/scikits/timeseries/extras.pyc in tsfromtxt(fname, dtype, freq, comments, delimiter, skiprows, converters, dateconverter, missing, missing_values, usecols, datecols, names, excludelist, deletechars, case_sensitive, unpack, loose, asrecarray)
    433     if len(dateinfo) == 1:
    434         dateinfo = np.array(dateinfo[0], copy=False, ndmin=1)
--> 435         dates = date_array([dateconv(args) for args in dateinfo],
    436                            freq=freq, autosort=False)
    437     else:

UnboundLocalError: local variable 'dateconv' referenced before assignment

What am I doing wrong?


- dharhas

More information about the SciPy-user mailing list