Skip to content
Back to top
View this page

# Columns and rows

`agate.MappedSequence` | A generic container for immutable data that can be accessed either by numeric index or by key.
`agate.Column` | Proxy access to column data.
`agate.Row` | A row of data.

class agate.MappedSequence(values, keys=None)

  Bases: `Sequence`

  A generic container for immutable data that can be accessed either by numeric index or by key. This is similar to an `collections.OrderedDict` except that the keys are optional and iteration over it returns the values instead of keys.

  This is the base class for both `Column` and `Row`.

  Parameters:

    - values – A sequence of values.

    - keys – A sequence of keys.

  keys()

    Equivalent to `collections.OrderedDict.keys()`.

  values()

    Equivalent to `collections.OrderedDict.values()`.

  items()

    Equivalent to `collections.OrderedDict.items()`.

  get(key, default=None)

    Equivalent to `collections.OrderedDict.get()`.

  dict()

    Retrieve the contents of this sequence as an `collections.OrderedDict`.

class agate.Column(index, name, data_type, rows, row_names=None)

  Bases: `MappedSequence`

  Proxy access to column data. Instances of `Column` should not be constructed directly. They are created by `Table` instances and are unique to them.

  Columns are implemented as subclass of `MappedSequence`. They deviate from the underlying implementation in that loading of their data is deferred until it is needed.

  Parameters:

    - name – The name of this column.

    - data_type – An instance of `DataType`.

    - rows – A `MappedSequence` that contains the `Row` instances containing the data for this column.

    - row_names – An optional list of row names (keys) for this column.

  property index

    This column’s index.

  property name

    This column’s name.

  property data_type

    This column’s data type.

  values()

    Get the values in this column, as a tuple.

  values_distinct()

    Get the distinct values in this column, as a tuple.

  values_without_nulls()

    Get the values in this column with any null values removed.

  values_sorted()

    Get the values in this column sorted.

  values_without_nulls_sorted()

    Get the values in this column with any null values removed and sorted.

class agate.Row(values, keys=None)

  Bases: `MappedSequence`

  A row of data. Values within a row can be accessed by column name or column index. Row are immutable and may be shared between `Table` instances.

  Currently row instances are a no-op subclass of `MappedSequence`. They are being maintained in this fashion in order to support future features.