astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v5.2.1 »
- Data Tables (`astropy.table`) »
- TableGroups

# TableGroups

class astropy.table.TableGroups(parent_table, indices=None, keys=None)

  Bases: `BaseGroups`

  Attributes Summary

  `indices` |
  `key_colnames` | Return the names of columns in the parent table that were used for grouping.
  `keys` |

  Methods Summary

  `aggregate`(func) | Aggregate each group in the Table into a single row by applying the reduction function `func` to group values in each column.
  `filter`(func) | Filter groups in the Table based on evaluating function `func` on each group sub-table.

  Attributes Documentation

  indices
  key_colnames

    Return the names of columns in the parent table that were used for grouping.

  keys

  Methods Documentation

  aggregate(func)

    Aggregate each group in the Table into a single row by applying the reduction function `func` to group values in each column.

    Parameters:
      func python:function

        Function that reduces an array of values to a single value

    Returns:
      out `Table`

        New table with the aggregated rows.

  filter(func)

    Filter groups in the Table based on evaluating function `func` on each group sub-table.

    The function which is passed to this method must accept two arguments:

    - `table` : `Table` object

    - `key_colnames` : tuple of column names in `table` used as keys for grouping

    It must then return either `True` or `False`. As an example, the following will select all table groups with only positive values in the non-key columns:

        def all_positive(table, key_colnames):
            colnames = [name for name in table.colnames if name not in key_colnames]
            for colname in colnames:
                if np.any(table[colname] < 0):
                    return False
            return True

    Parameters:
      func python:function

        Filter function

    Returns:
      out `Table`

        New table with the aggregated rows.