larray.Axis¶
-
class
larray.Axis(labels, name=None)[source]¶ Represents an axis. It consists of a name and a list of labels.
Parameters: - labels : array-like or int
collection of values usable as labels, i.e. numbers or strings or the size of the axis. In the last case, a wildcard axis is created.
- name : str or Axis, optional
name of the axis or another instance of Axis. In the second case, the name of the other axis is simply copied. By default None.
Examples
>>> gender = Axis(['M', 'F'], 'gender') >>> gender Axis(['M', 'F'], 'gender') >>> gender.name 'gender' >>> list(gender.labels) ['M', 'F']
using a string definition
>>> gender = Axis('gender=M,F') >>> gender Axis(['M', 'F'], 'gender') >>> age = Axis('age=0..9') >>> age Axis([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'age') >>> code = Axis('code=A,C..E,F..G,Z') >>> code Axis(['A', 'C', 'D', 'E', 'F', 'G', 'Z'], 'code')
a wildcard axis only needs a length
>>> row = Axis(10, 'row') >>> row Axis(10, 'row') >>> row.labels array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
axes can also be defined without name
>>> anonymous = Axis('0..4') >>> anonymous Axis([0, 1, 2, 3, 4], None)
Attributes: labels: array-like or intlabels of the axis.
- name : str
name of the axis. None in the case of an anonymous axis.
Methods
__init__(labels[, name])Initialize self. align(other[, join])Align axis with other object using specified join method. all([name])(Deprecated) Returns a group containing all labels. apply(func)Returns a new axis with the labels transformed by func. astype(dtype, numpy.dtype], casting)Cast labels to a specified type. by(length[, step, template])Split axis into several groups of specified length. containing(substring)Returns a group with all the labels containing the specified substring. copy()Returns a copy of the axis. difference(other)Returns axis with the (set) difference of this axis labels and other labels. endingwith(suffix)Returns a group with the labels ending with the specified string. endswith(**kwargs)equals(other)Checks if self is equal to another axis. extend(labels)Append new labels to an axis or increase its length in case of wildcard axis. group(*args[, name])ignore_labels()Returns a wildcard axis with the same name and length than this axis. index(key)Translates a label key to its numerical index counterpart. insert(new_labels[, before, after])Return a new axis with new_labels inserted before before or after after. intersection(other)Returns axis with the (set) intersection of this axis labels and other labels. iscompatible(other)Checks if self is compatible with another axis. labels_summary()Returns a short representation of the labels. matches(**kwargs)matching([deprecated, pattern, regex])Returns a group with all the labels matching the specified pattern or regular expression. max()Get maximum of labels. min()Get minimum of labels. rename(name)Renames the axis. replace(old[, new])Returns a new axis with some labels replaced. split([sep, names, regex, return_labels])Split axis and returns a list of Axis. startingwith(prefix)Returns a group with the labels starting with the specified string. startswith(**kwargs)subaxis(key)Returns an axis for a sub-array. to_hdf(filepath[, key])Writes axis to a HDF file. translate(**kwargs)union(other)Returns axis with the union of this axis labels and other labels. Attributes
dtypeiAllows to define a subset using positions along the axis instead of labels. idiswildcardlabelslabels of the axis. name