mvpa2.misc.io.base.ColumnData

Inheritance diagram of ColumnData

class mvpa2.misc.io.base.ColumnData(source, header=True, sep=None, headersep=None, dtype=<type 'float'>, skiplines=0)

Read data that is stored in columns of text files.

All read data is available via a dictionary-like interface. If column headers are available, the column names serve as dictionary keys. If no header exists an articfical key is generated: str(number_of_column).

Splitting of text file lines is performed by the standard split() function (which gets passed the sep argument as separator string) and each element is converted into the desired datatype.

Because data is read into a dictionary no two columns can have the same name in the header! Each column is stored as a list in the dictionary.

Methods

clear(() -> None.  Remove all items from D.)
copy(() -> a shallow copy of D)
fromkeys(...) v defaults to None.
get((k[,d]) -> D[k] if k in D, ...)
has_key((k) -> True if D has a key k, else False)
items(() -> list of D’s (key, value) pairs, ...)
iteritems(() -> an iterator over the (key, ...)
iterkeys(() -> an iterator over the keys of D)
itervalues(...)
keys(() -> list of D’s keys)
pop((k[,d]) -> v, ...) If key is not found, d is returned if given, otherwise KeyError is raised
popitem(() -> (k, v), ...) 2-tuple; but raise KeyError if D is empty.
select_samples(selection) Return new ColumnData with selected samples
setdefault((k[,d]) -> D.get(k,d), ...)
tofile(filename[, header, header_order, sep]) Write column data to a text file.
update(([E, ...) If E present and has a .keys() method, does: for k in E: D[k] = E[k]
values(() -> list of D’s values)
viewitems(...)
viewkeys(...)
viewvalues(...)

Read data from file into a dictionary.

Parameters:

source : str or dict

If values is given as a string all data is read from the file and additonal keyword arguments can be used to customize the read procedure. If a dictionary is passed a deepcopy is performed.

header : bool or list of str

Indicates whether the column names should be read from the first line (header=True). If header=False unique column names will be generated (see class docs). If header is a python list, it’s content is used as column header names and its length has to match the number of columns in the file.

sep : str or None

Separator string. The actual meaning depends on the output format (see class docs).

headersep : str or None

Separator string used in the header. The actual meaning depends on the output format (see class docs).

dtype : type or list(types)

Desired datatype(s). Datatype per column get be specified by passing a list of types.

skiplines : int

Number of lines to skip at the beginning of the file.

Methods

clear(() -> None.  Remove all items from D.)
copy(() -> a shallow copy of D)
fromkeys(...) v defaults to None.
get((k[,d]) -> D[k] if k in D, ...)
has_key((k) -> True if D has a key k, else False)
items(() -> list of D’s (key, value) pairs, ...)
iteritems(() -> an iterator over the (key, ...)
iterkeys(() -> an iterator over the keys of D)
itervalues(...)
keys(() -> list of D’s keys)
pop((k[,d]) -> v, ...) If key is not found, d is returned if given, otherwise KeyError is raised
popitem(() -> (k, v), ...) 2-tuple; but raise KeyError if D is empty.
select_samples(selection) Return new ColumnData with selected samples
setdefault((k[,d]) -> D.get(k,d), ...)
tofile(filename[, header, header_order, sep]) Write column data to a text file.
update(([E, ...) If E present and has a .keys() method, does: for k in E: D[k] = E[k]
values(() -> list of D’s values)
viewitems(...)
viewkeys(...)
viewvalues(...)
ncolumns

Returns the number of columns.

nrows

Returns the number of rows.

select_samples(selection)

Return new ColumnData with selected samples

tofile(filename, header=True, header_order=None, sep=' ')

Write column data to a text file.

Parameters:

filename : str

Target filename

header : bool, optional

If True a column header is written, using the column keys. If False no header is written.

header_order : None or list of str

If it is a list of strings, they will be used instead of simply asking for the dictionary keys. However these strings must match the dictionary keys in number and identity. This argument type can be used to determine the order of the columns in the output file. The default value is None. In this case the columns will be in an arbitrary order.

sep : str, optional

String that is written as a separator between to data columns.