<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "TabularData",
  "identifier" : "/documentation/TabularData/RowGroupingProtocol",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "TabularData"
    ],
    "preciseIdentifier" : "s:11TabularData19RowGroupingProtocolP"
  },
  "title" : "RowGroupingProtocol"
}
-->

# RowGroupingProtocol

A type that represents a collection of row selections that have the same value in a column.

```
protocol RowGroupingProtocol : CustomStringConvertible
```

## Topics

### Inspecting a Row Grouping

[`var count: Int`](/documentation/TabularData/RowGroupingProtocol/count)

The number of groups in the row grouping.

### Transforming a Row Grouping

[`func mapGroups((DataFrame.Slice) throws -> DataFrame) rethrows -> Self`](/documentation/TabularData/RowGroupingProtocol/mapGroups(_:))

Generates a row grouping that applies a transformation closure to each group in the original.

### Splitting a Row Grouping

[`func randomSplit(by: Double) -> (Self, Self)`](/documentation/TabularData/RowGroupingProtocol/randomSplit(by:))

Generates two row groupings by randomly splitting the original with a proportion.

[`func randomSplit(by: Double, seed: Int?) -> (Self, Self)`](/documentation/TabularData/RowGroupingProtocol/randomSplit(by:seed:))

Generates two row groupings by randomly splitting the original by a proportion.

### Aggregating a Row Grouping

[`func counts() -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/counts())

Generates a data frame with two columns, one that has a row for each group key and another for the number of
rows in the group.

[`func counts(order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/counts(order:))

Generates a data frame, that you choose how to sort, with two columns, one that has a row for each group key and
another for the number or rows in the group.

[`func sums<N>(String, N.Type, order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/sums(_:_:order:))

Generates a data frame that contains the sum of each group’s rows along a column you select
by name.

[`func sums<N>(ColumnID<N>, order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/sums(_:order:))

Generates a data frame that contains the sum of each group’s rows along a column you select
by column identifier.

[`func means<N>(String, N.Type, order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/means(_:_:order:))

Generates a data frame that contains the average mean of each group’s rows along a column you select
by name.

[`func means<N>(ColumnID<N>, order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/means(_:order:))

Generates a data frame that contains the average mean of each group’s rows along a column you select
by column identifier.

[`func minimums<N>(String, N.Type, order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/minimums(_:_:order:))

Generates a data frame that contains the minimums of each group’s rows along a column you select
by name.

[`func minimums<N>(ColumnID<N>, order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/minimums(_:order:))

Generates a data frame that contains the minimums of each group’s rows along a column you select
by column identifier.

[`func maximums<N>(String, N.Type, order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/maximums(_:_:order:))

Generates a data frame that contains the maximums of each group’s rows along a column you select
by name.

[`func maximums<N>(ColumnID<N>, order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/maximums(_:order:))

Generates a data frame that contains the maximums of each group’s rows along a column you select
by column identifier.

[`func aggregated<Element, Result>(on: ColumnID<Element>, into: String?, transform: (DiscontiguousColumnSlice<Element>) throws -> Result) rethrows -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/aggregated(on:into:transform:))

Generates a data frame with a column for the group identifier and a column of values from the transform.

[`func aggregated<Element, Result>(on: [String], naming: (String) -> String, transform: (DiscontiguousColumnSlice<Element>) throws -> Result?) rethrows -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/aggregated(on:naming:transform:))

Generates a data frame by aggregating each group’s contents for each column you select by name.

### Flattening a Row Grouping

[`func ungrouped() -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/ungrouped())

Generates a data frame that contains all the rows from each group in the row grouping.

### Summarizing a Row Grouping

[`func summary() -> any GroupSummaries`](/documentation/TabularData/RowGroupingProtocol/summary())

Generates a group summaries instance of the row grouping’s columns.

[`func summary(of: [String]) -> any GroupSummaries`](/documentation/TabularData/RowGroupingProtocol/summary(of:))

Generates a group summaries instance of the row grouping’s columns you select by name.

[`protocol GroupSummaries`](/documentation/TabularData/GroupSummaries)

A collection of group summaries.

### Instance Methods

[`func filter((DataFrame.Slice) throws -> Bool) rethrows -> Self`](/documentation/TabularData/RowGroupingProtocol/filter(_:))

Returns a row grouping containing only the groups that satisfy a predicate.

[`func quantiles<N>(String, N.Type, quantile: N, order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/quantiles(_:_:quantile:order:))

Generates a data frame that contains the quantile of each group’s rows along a column you select
by name.

[`func quantiles<N>(ColumnID<N>, quantile: N, order: Order?) -> DataFrame`](/documentation/TabularData/RowGroupingProtocol/quantiles(_:quantile:order:))

Generates a data frame that contains the quantiles of each group’s rows along a column you select
by column identifier.

### Subscripts

[`subscript(Any?...) -> DataFrame.Slice?`](/documentation/TabularData/RowGroupingProtocol/subscript(_:))

Retrieves a group slice by key.

## Relationships

### Conforming Types

[`RowGrouping`](/documentation/TabularData/RowGrouping)

### Inherits From

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)