<!--
{
  "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/DataFrameProtocol",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "TabularData"
    ],
    "preciseIdentifier" : "s:11TabularData0B13FrameProtocolP"
  },
  "title" : "DataFrameProtocol"
}
-->

# DataFrameProtocol

A type that represents a data frame.

```
protocol DataFrameProtocol
```

## Topics

### Inspecting a Data Frame Type

[`var isEmpty: Bool`](/documentation/TabularData/DataFrameProtocol/isEmpty)

A Boolean that indicates whether the data frame type is empty.

[`var shape: (rows: Int, columns: Int)`](/documentation/TabularData/DataFrameProtocol/shape)

The number or rows and columns of the data frame type.

[`var columns: [Self.ColumnType]`](/documentation/TabularData/DataFrameProtocol/columns)

The columns of the underlying data frame.

[`associatedtype ColumnType : AnyColumnProtocol`](/documentation/TabularData/DataFrameProtocol/ColumnType)

A type that conforms to the type-erased column protocol.

[`var rows: DataFrame.Rows`](/documentation/TabularData/DataFrameProtocol/rows)

The rows of the underlying data frame.

[`struct Rows`](/documentation/TabularData/DataFrame/Rows-swift.struct)

A collection of rows in a data frame.

[`var base: DataFrame`](/documentation/TabularData/DataFrameProtocol/base)

The underlying data frame.

### Accessing Rows

[`subscript(Range<Int>) -> DataFrame.Slice`](/documentation/TabularData/DataFrameProtocol/subscript(_:))

Accesses a slice of the data frame type with an index range.

[`subscript<R>(R) -> DataFrame.Slice`](/documentation/TabularData/DataFrameProtocol/subscript(_:)-8hly3)

Accesses rows of a data frame type with an index range expression.

### Creating Two Slices by Splitting Rows

[`func randomSplit(by: Double, seed: Int?) -> (DataFrame.Slice, DataFrame.Slice)`](/documentation/TabularData/DataFrameProtocol/randomSplit(by:seed:))

Generates two data frame slices by randomly splitting the rows of the data table.

[`func randomSplit<G>(by: Double, using: inout G) -> (DataFrame.Slice, DataFrame.Slice)`](/documentation/TabularData/DataFrameProtocol/randomSplit(by:using:))

Generates two data frame slices by randomly splitting the rows of the data table type
with a random-number generator.

### Creating Two Data Frames by Splitting Rows

[`func stratifiedSplit(on: String, by: Double, randomSeed: Int?) -> (DataFrame, DataFrame)`](/documentation/TabularData/DataFrameProtocol/stratifiedSplit(on:by:randomSeed:)-9iauf)

Generates two data frames by randomly splitting the rows of a column,
which you select by its name, into strata.

[`func stratifiedSplit(on: String..., by: Double, randomSeed: Int?) -> (DataFrame, DataFrame)`](/documentation/TabularData/DataFrameProtocol/stratifiedSplit(on:by:randomSeed:)-8szu1)

Generates two data frames by randomly splitting the rows of multiple columns,
which you select by their names, into strata.

[`func stratifiedSplit<T>(on: ColumnID<T>, by: Double, randomSeed: Int?) -> (DataFrame, DataFrame)`](/documentation/TabularData/DataFrameProtocol/stratifiedSplit(on:by:randomSeed:)-714jk)

Generates two data frames by randomly splitting the rows of a column,
which you select by column identifier,
into strata.

[`func stratifiedSplit<T0, T1>(on: ColumnID<T0>, ColumnID<T1>, by: Double, randomSeed: Int?) -> (DataFrame, DataFrame)`](/documentation/TabularData/DataFrameProtocol/stratifiedSplit(on:_:by:randomSeed:))

Generates two data frames by randomly splitting the rows of two columns, which you select by column identifiers,
into strata.

[`func stratifiedSplit<T0, T1, T2>(on: ColumnID<T0>, ColumnID<T1>, ColumnID<T2>, by: Double, randomSeed: Int?) -> (DataFrame, DataFrame)`](/documentation/TabularData/DataFrameProtocol/stratifiedSplit(on:_:_:by:randomSeed:))

Generates two data frames by randomly splitting the rows of three columns,
which you select by column identifiers, into strata.

### Creating a Data Frame by Sorting a Column

[`func sorted(on: String, order: Order) -> DataFrame`](/documentation/TabularData/DataFrameProtocol/sorted(on:order:)-818u5)

Generates a data frame by copying the data frame’s rows and then sorting the rows according to a column
that you select by its name.

[`func sorted<T>(on: String, T.Type, order: Order) -> DataFrame`](/documentation/TabularData/DataFrameProtocol/sorted(on:_:order:)-8d7rr)

Generates a data frame by copying the data frame’s rows and then sorting the rows according to a column
that you select by its name and type.

[`func sorted<T>(on: String, T.Type, by: (T, T) throws -> Bool) rethrows -> DataFrame`](/documentation/TabularData/DataFrameProtocol/sorted(on:_:by:))

Generates a data frame by copying the data frame’s rows and then sorting the rows according to a column
that you select by its name and type, with a predicate.

[`func sorted<T>(on: ColumnID<T>, order: Order) -> DataFrame`](/documentation/TabularData/DataFrameProtocol/sorted(on:order:)-5nl5c)

Generates a data frame by copying the data frame’s rows and then sorting the rows according to a column
that you select by its column identifier.

[`func sorted<T>(on: ColumnID<T>, by: (T, T) throws -> Bool) rethrows -> DataFrame`](/documentation/TabularData/DataFrameProtocol/sorted(on:by:))

Generates a data frame by copying the data frame’s rows and then sorting the rows according to a column
that you select by its column identifier, with a predicate.

### Creating a Data Frame by Sorting Multiple Columns

[`func sorted<T0, T1>(on: ColumnID<T0>, ColumnID<T1>, order: Order) -> DataFrame`](/documentation/TabularData/DataFrameProtocol/sorted(on:_:order:)-79los)

Generates a data frame by copying the data frame’s rows and then sorting the rows according to two columns
that you select by their column identifiers.

[`func sorted<T0, T1, T2>(on: ColumnID<T0>, ColumnID<T1>, ColumnID<T2>, order: Order) -> DataFrame`](/documentation/TabularData/DataFrameProtocol/sorted(on:_:_:order:))

Generates a data frame by copying the data frame’s rows and then sorting the rows according to three columns
that you select by their column identifiers.

### Creating a Data Frame by Joining Another Data Frame

[`func joined<R>(R, on: String, kind: JoinKind) -> DataFrame`](/documentation/TabularData/DataFrameProtocol/joined(_:on:kind:)-1gp6k)

Generates a data frame by joining with another data frame type with a common column you select by name.

[`func joined<R>(R, on: (left: String, right: String), kind: JoinKind) -> DataFrame`](/documentation/TabularData/DataFrameProtocol/joined(_:on:kind:)-7u2tw)

Generates a data frame by joining with another data frame type along
the columns that you select by name for both data frame types.

[`func joined<R, T>(R, on: (left: ColumnID<T>, right: ColumnID<T>), kind: JoinKind) -> DataFrame`](/documentation/TabularData/DataFrameProtocol/joined(_:on:kind:)-9629e)

Generates a data frame by joining with another data frame type along
the columns that you select by identifier for both data frame types.

[`func joined<R, T>(R, on: ColumnID<T>, kind: JoinKind) -> DataFrame`](/documentation/TabularData/DataFrameProtocol/joined(_:on:kind:)-mvic)

Generates a data frame by joining with another data frame type with a common column
that you select by identifier.

[`enum JoinKind`](/documentation/TabularData/JoinKind)

An operation type that joins two data frame types.

### Creating a Row Grouping by a Column

[`func grouped<GroupingKey>(by: ColumnID<GroupingKey>) -> RowGrouping<GroupingKey>`](/documentation/TabularData/DataFrameProtocol/grouped(by:)-77mq2)

Creates a grouping of rows that the method selects
by choosing unique values in a column.

[`func grouped(by: String, timeUnit: Calendar.Component) -> RowGrouping<Int>`](/documentation/TabularData/DataFrameProtocol/grouped(by:timeUnit:)-7s782)

Creates a grouping of rows that the method selects
by choosing unique units of time in a date column you select by name.

[`func grouped(by: ColumnID<Date>, timeUnit: Calendar.Component) -> RowGrouping<Int>`](/documentation/TabularData/DataFrameProtocol/grouped(by:timeUnit:)-78cy)

Creates a grouping of rows that the method selects
by choosing unique units of time in a date column you select by column identifier.

[`func grouped<InputKey, GroupingKey>(by: String, transform: (InputKey?) -> GroupingKey?) -> RowGrouping<GroupingKey>`](/documentation/TabularData/DataFrameProtocol/grouped(by:transform:)-3cr4p)

Creates a grouping of rows that the method selects
by choosing unique values the transform closure creates with elements of a
column you select by name.

[`func grouped<InputKey, GroupingKey>(by: ColumnID<InputKey>, transform: (InputKey?) -> GroupingKey?) -> RowGrouping<GroupingKey>`](/documentation/TabularData/DataFrameProtocol/grouped(by:transform:)-3aade)

Creates a grouping of rows that the method selects
by choosing unique values the transform closure creates with elements of a
column you select by column identifier.

### Creating a Row Grouping by Multiple Columns

[`func grouped(by: String...) -> some RowGroupingProtocol`](/documentation/TabularData/DataFrameProtocol/grouped(by:)-4wcw6)

Creates a grouping from multiple columns you select by name.

[`func grouped<T>(by: ColumnID<T>...) -> some RowGroupingProtocol`](/documentation/TabularData/DataFrameProtocol/grouped(by:)-6m6to)

Creates a grouping from multiple columns that you select by column identifier.

[`func grouped<T0, T1>(by: ColumnID<T0>, ColumnID<T1>) -> some RowGroupingProtocol`](/documentation/TabularData/DataFrameProtocol/grouped(by:_:))

Creates a grouping from two columns of different types.

[`func grouped<T0, T1, T2>(by: ColumnID<T0>, ColumnID<T1>, ColumnID<T2>) -> some RowGroupingProtocol`](/documentation/TabularData/DataFrameProtocol/grouped(by:_:_:))

Creates a grouping from three columns of different types.

### Saving a Data Frame Type to a CSV Format

[`func writeCSV(to: URL, options: CSVWritingOptions) throws`](/documentation/TabularData/DataFrameProtocol/writeCSV(to:options:))

Creates a CSV file with the contents of the data frame type.

[`func csvRepresentation(options: CSVWritingOptions) throws -> Data`](/documentation/TabularData/DataFrameProtocol/csvRepresentation(options:))

Generates a CSV data instance of the data frame type.

### Describing a Data Frame Type

[`func description(options: FormattingOptions) -> String`](/documentation/TabularData/DataFrameProtocol/description(options:))

Generates a text representation of the data frame type.

### Supporting Types

### Instance Methods

[`func jsonRepresentation(options: JSONWritingOptions) throws -> Data`](/documentation/TabularData/DataFrameProtocol/jsonRepresentation(options:))

Generates a JSON data instance of the data frame.

[`func writeJSON(to: URL, options: JSONWritingOptions) throws`](/documentation/TabularData/DataFrameProtocol/writeJSON(to:options:))

Creates a JSON file with the contents of the data frame.

## Relationships

### Conforming Types

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

[`Slice`](/documentation/TabularData/DataFrame/Slice)

---

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)