The scikits.timeseries package provides a convenient way to create a TimeSeries object from the information stored in an ASCII file.
Load a TimeSeries from a text file.
Each line of the input after the first skiprows ones is split at delimiter. Characters occuring after comments are discarded.
If a column is named 'dates' (case insensitive), it is used to define the dates. The freq parameter should be set to the expected frequency of the output series. If the date information spans several columns (for example, year in col #1, month in col #2...), a specific conversion function must be defined with the dateconverter parameter. This function should accept as many inputs as date columns, and return a valid Date object.
Parameters: | fname : file or string
dtype : data-type, optional
comments : {string}, optional
delimiter : {string}, optional
skip_header : int, optional
skip_footer : int, optional
converters : variable or None, optional
dateconverter : {function}, optional
missing_values : variable or None, optional
filling_values : variable or None, optional
usecols : sequence or None, optional
datecols : {None, int, sequence}, optional
names : {None, True, str, sequence}, optional
excludelist : sequence, optional
deletechars : str, optional
defaultfmt : str, optional
autostrip : bool, optional
case_sensitive : {True, False, ‘upper’, ‘lower’}, optional
unpack : bool, optional
usemask : bool, optional
asrecarray : {False, True}, optional
invalid_raise : bool, optional
|
---|---|
Returns: | out : MaskedArray
|
See also
Notes
Examples
>>> data = "year, month, a, b\n 2001, 01, 0.0, 10.\n 2001, 02, 1.1, 11."
>>> dateconverter = lambda y, m: Date('M', year=int(y), month=int(m))
>>> series = tsfromtxt(StringIO.StringIO(data), delimiter=',', names=True,
... datecols=(0,1), dateconverter=dateconverter,)
>>> series
timeseries([(0.0, 10.0) (1.1, 11.0)],
dtype = [('a', '<f8'), ('b', '<f8')],
dates = [Jan-2001 Feb-2001],
freq = M)
>>> series = tsfromtxt(StringIO.StringIO(data), delimiter=",",
... datecols=(0, 1), dateconverter=dateconverter,
... names="A, B", skip_header=1)
timeseries([(0.0, 10.0) (1.1000000000000001, 11.0)],
dtype = [('A', '<f8'), ('B', '<f8')],
dates = [Jan-2001 Feb-2001],
freq = M)
Several options are available to store a TimeSeries object to an ASCII file.
A first possibility is to use the numpy.savetxt function on a structured array, after having converted the object with the toflex method.
Another possibility is to use the Report class, described in the Reports section.