def group(self, column_or_label, collect=None):
<EOL>if _is_non_string_iterable(column_or_label) andlen(column_or_label) != self._num_rows:<EOL><INDENT>return self.groups(column_or_label, collect)<EOL><DEDENT>self = self.copy(shallow=True)<EOL>collect = _zero_on_type_error(collect)<EOL>column = self._get_column(column_or_label)<EOL>if isinstance(column_or_label, str) or isinstance(column_or_label, numbers.Integral):<EOL><INDENT>column_label = self._as_label(column_or_label)<EOL>del self[column_label]<EOL><DEDENT>else:<EOL><INDENT>column_label = self._unused_label('<STR_LIT>')<EOL><DEDENT>groups = self.index_by(column)<EOL>keys = sorted(groups.keys())<EOL>if collect is None:<EOL><INDENT>labels = [column_label, '<STR_LIT:count>' if column_label != '<STR_LIT:count>' else self._unused_label('<STR_LIT:count>')]<EOL>columns = [keys, [len(groups[k]) for k in keys]]<EOL><DEDENT>else:<EOL><INDENT>columns, labels = [], []<EOL>for i, label in enumerate(self.labels):<EOL><INDENT>labels.append(_collected_label(collect, label))<EOL>c = [collect(np.array([row[i] for row in groups[k]])) for k in keys]<EOL>columns.append(c)<EOL><DEDENT><DEDENT>grouped = type(self)().with_columns(zip(labels, columns))<EOL>assert column_label == self._unused_label(column_label)<EOL>grouped[column_label] = keys<EOL>grouped.move_to_start(column_label)<EOL>return grouped<EOL>
Group rows by unique values in a column; count or aggregate others.

        Args:
            ``column_or_label``: values to group (column label or index, or array)

            ``collect``: a function applied to values in other columns for each group

        Returns:
            A Table with each row corresponding to a unique value in ``column_or_label``,
            where the first column contains the unique values from ``column_or_label``, and the
            second contains counts for each of the unique values. If ``collect`` is
            provided, a Table is returned with all original columns, each containing values
            calculated by first grouping rows according to ``column_or_label``, then applying
            ``collect`` to each set of grouped values in the other columns.

        Note:
            The grouped column will appear first in the result table. If ``collect`` does not
            accept arguments with one of the column types, that column will be empty in the resulting
            table.

        >>> marbles = Table().with_columns(
        ...    "Color", make_array("Red", "Green", "Blue", "Red", "Green", "Green"),
        ...    "Shape", make_array("Round", "Rectangular", "Rectangular", "Round", "Rectangular", "Round"),
        ...    "Amount", make_array(4, 6, 12, 7, 9, 2),
        ...    "Price", make_array(1.30, 1.30, 2.00, 1.75, 1.40, 1.00))
        >>> marbles
        Color | Shape       | Amount | Price
        Red   | Round       | 4      | 1.3
        Green | Rectangular | 6      | 1.3
        Blue  | Rectangular | 12     | 2
        Red   | Round       | 7      | 1.75
        Green | Rectangular | 9      | 1.4
        Green | Round       | 2      | 1
        >>> marbles.group("Color") # just gives counts
        Color | count
        Blue  | 1
        Green | 3
        Red   | 2
        >>> marbles.group("Color", max) # takes the max of each grouping, in each column
        Color | Shape max   | Amount max | Price max
        Blue  | Rectangular | 12         | 2
        Green | Round       | 9          | 1.4
        Red   | Round       | 7          | 1.75
        >>> marbles.group("Shape", sum) # sum doesn't make sense for strings
        Shape       | Color sum | Amount sum | Price sum
        Rectangular |           | 27         | 4.7
        Round       |           | 13         | 4.05