<!--
{
  "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/DataFrame/Slice",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "TabularData"
    ],
    "preciseIdentifier" : "s:11TabularData0B5FrameV5SliceV"
  },
  "title" : "DataFrame.Slice"
}
-->

# DataFrame.Slice

A set of a data frame’s rows you create by using a method from a data frame instance
or another data frame slice.

```
@dynamicMemberLookup struct Slice
```

## Overview

A slice is an arbitrary set of rows from a data frame.
For example, a slice might contain rows 0–3, 5–9, and 101 from its underlying data frame.

## Topics

### Inspecting a Slice

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

The number of rows and columns in the slice.

[`var columns: [AnyColumnSlice]`](/documentation/TabularData/DataFrame/Slice/columns)

The entire slice as a collection of columns.

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

The entire slice as a collection of rows.

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

The underlying data frame.

### Accessing Rows

### Creating a Slice by Selecting a Column

[`subscript<T>(ColumnID<T>) -> DiscontiguousColumnSlice<T>`](/documentation/TabularData/DataFrame/Slice/subscript(_:)-32h9z)

Returns a column you select by its column identifier.

[`subscript<T>(column _: Int, T.Type) -> DiscontiguousColumnSlice<T>`](/documentation/TabularData/DataFrame/Slice/subscript(column:_:))

Returns a column you select by its index.

[`subscript<T>(String, T.Type) -> DiscontiguousColumnSlice<T>`](/documentation/TabularData/DataFrame/Slice/subscript(_:_:))

Returns a column you select by its name and type.

[`subscript(String) -> AnyColumnSlice`](/documentation/TabularData/DataFrame/Slice/subscript(_:)-18kdy)

Returns a column you select by its name.

[`subscript(dynamicMember _: String) -> AnyColumnSlice`](/documentation/TabularData/DataFrame/Slice/subscript(dynamicMember:))

Returns a column you select by its name to support dynamic-member lookup.

### Creating a Slice by Selecting Multiple Columns

[`subscript<S>(S) -> DataFrame.Slice`](/documentation/TabularData/DataFrame/Slice/subscript(_:)-5y42o)

Generates a data frame slice that includes the columns in a sequence of column names.

[`func selecting<S>(columnNames: S) -> DataFrame.Slice`](/documentation/TabularData/DataFrame/Slice/selecting(columnNames:)-9l8oe)

Generates a data frame slice that includes the columns you select with a sequence of names.

[`func selecting(columnNames: String...) -> DataFrame.Slice`](/documentation/TabularData/DataFrame/Slice/selecting(columnNames:)-48kji)

Generates a data frame slice that includes the columns you select with a list of names.

### Creating a Slice by Selecting Rows

[`func prefix(Int) -> DataFrame.Slice`](/documentation/TabularData/DataFrame/Slice/prefix(_:))

Returns a new slice that contains the initial elements of the original slice.

[`func prefix(upTo: Int) -> DataFrame.Slice`](/documentation/TabularData/DataFrame/Slice/prefix(upTo:))

Returns a new slice that contains the initial elements of the original slice
up to, but not including, the element at a position.

[`func prefix(through: Int) -> DataFrame.Slice`](/documentation/TabularData/DataFrame/Slice/prefix(through:))

Returns a new slice that contains the initial elements of the original slice
up to and including the element at a position.

[`func suffix(Int) -> DataFrame.Slice`](/documentation/TabularData/DataFrame/Slice/suffix(_:))

Returns a new slice that contains the final elements of the original slice.

[`func suffix(from: Int) -> DataFrame.Slice`](/documentation/TabularData/DataFrame/Slice/suffix(from:))

Returns a new slice that contains the final elements of the original slice
beginning with the element at a position.

### Creating a Slice by Filtering Rows

[`func filter<T>(on: ColumnID<T>, (T?) throws -> Bool) rethrows -> DataFrame.Slice`](/documentation/TabularData/DataFrame/Slice/filter(on:_:))

Returns a selection of rows that satisfy a predicate in the columns you select by column identifier.

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

Returns a selection of rows that satisfy a predicate in the columns you select by name.

### Creating Two Slices by Splitting Rows

### Creating Two Data Frames by Splitting Rows

### Creating a Data Frame by Sorting a Column

### Creating a Data Frame by Sorting Multiple Columns

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

### Grouping Rows

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

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

[`func grouped(by: String) -> any RowGroupingProtocol`](/documentation/TabularData/DataFrame/Slice/grouped(by:))

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

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

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

### Summarizing a Slice

[`func summary() -> DataFrame`](/documentation/TabularData/DataFrame/Slice/summary())

Generates a data frame that summarizes the columns of the data frame slice.

[`func summary(of: String...) -> DataFrame`](/documentation/TabularData/DataFrame/Slice/summary(of:))

Generates a data frame that summarizes the columns you select by name.

[`func summary(ofColumns: Int...) -> DataFrame`](/documentation/TabularData/DataFrame/Slice/summary(ofColumns:))

Generates a data frame that summarizes the columns you select by index.

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

The summary data frame column identifiers.

### Saving a Slice to a CSV

### Comparing Slices

[`static func == (DataFrame.Slice, DataFrame.Slice) -> Bool`](/documentation/TabularData/DataFrame/Slice/==(_:_:))

Returns a Boolean that indicates whether the slices are equal.

### Describing a Slice

[`var description: String`](/documentation/TabularData/DataFrame/Slice/description)

A text representation of the data frame slice.

[`var debugDescription: String`](/documentation/TabularData/DataFrame/Slice/debugDescription)

A text representation of the data frame slice suitable for debugging.

[`var customMirror: Mirror`](/documentation/TabularData/DataFrame/Slice/customMirror)

A mirror that reflects the data frame slice.

### Hashing a Slice

[`func hash(into: inout Hasher)`](/documentation/TabularData/DataFrame/Slice/hash(into:))

Hashes the essential components of the data frame slice by feeding them into a hasher.

### Default Implementations

[CustomDebugStringConvertible Implementations](/documentation/TabularData/DataFrame/Slice/CustomDebugStringConvertible-Implementations)

[CustomReflectable Implementations](/documentation/TabularData/DataFrame/Slice/CustomReflectable-Implementations)

[CustomStringConvertible Implementations](/documentation/TabularData/DataFrame/Slice/CustomStringConvertible-Implementations)

[Equatable Implementations](/documentation/TabularData/DataFrame/Slice/Equatable-Implementations)

[Hashable Implementations](/documentation/TabularData/DataFrame/Slice/Hashable-Implementations)

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

---

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)