<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLDataColumn",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML12MLDataColumnV"
  },
  "title" : "MLDataColumn"
}
-->

# MLDataColumn

A column of typed values in a data table.

```
struct MLDataColumn<Element> where Element : MLDataValueConvertible
```

## Overview

A column is a homogenous collection of data values, similar to an
<doc://com.apple.documentation/documentation/Swift/Array>. Columns are the main components of an [`MLDataTable`](/documentation/CreateML/MLDataTable)
and are designed to efficiently scale with large data sets.

Typically you use [`MLDataColumn`](/documentation/CreateML/MLDataColumn), the typed equivalent to [`MLUntypedColumn`](/documentation/CreateML/MLUntypedColumn), to work directly with the column’s
element type. A data column has extra math and statistics functionality when its element type is
<doc://com.apple.documentation/documentation/Swift/Int> or
<doc://com.apple.documentation/documentation/Swift/Double>.

## Topics

### Creating a data column

[`init(repeating:count:)`](/documentation/CreateML/MLDataColumn/init(repeating:count:))

Creates a new column with a repeating element.

[`init<S>(S)`](/documentation/CreateML/MLDataColumn/init(_:))

Creates a new column from a given sequence of elements.

[`init()`](/documentation/CreateML/MLDataColumn/init())

Constructs an invalid Column.

### Creating a data column by converting another column

[`func map<T>(to: T.Type) -> MLDataColumn<T>`](/documentation/CreateML/MLDataColumn/map(to:))

Creates a new column by converting this column to the given type.

[`init(column:)`](/documentation/CreateML/MLDataColumn/init(column:))

Creates a new column of machine learning sequences from a given column whose elements can be converted to
sequences.

[`init<T>(column: MLDataColumn<T>)`](/documentation/CreateML/MLDataColumn/init(column:)-5rg9u)

Creates a new column of integers from a given column whose elements can be converted to integers.

[`init<T>(column: MLDataColumn<T>)`](/documentation/CreateML/MLDataColumn/init(column:)-2rxtu)

Creates a new column of arrays of integers from a given column whose elements can be converted to an array of
integers.

[`init<T>(column: MLDataColumn<T>)`](/documentation/CreateML/MLDataColumn/init(column:)-86ge9)

Creates a new column of doubles from a given column whose elements can be converted to doubles.

[`init<T>(column: MLDataColumn<T>)`](/documentation/CreateML/MLDataColumn/init(column:)-23pmx)

Creates a new column of arrays of doubles from a given column whose elements can be converted to an array of
doubles.

[`init<T>(column: MLDataColumn<T>)`](/documentation/CreateML/MLDataColumn/init(column:)-ztkv)

Creates a new column of strings from a given column whose elements can be converted to strings.

[`init<T>(column: MLDataColumn<T>)`](/documentation/CreateML/MLDataColumn/init(column:)-8uzuq)

Creates a new column of arrays of strings from a given column whose elements can be converted to an array of
strings.

[`init<T>(column: MLDataColumn<T>)`](/documentation/CreateML/MLDataColumn/init(column:)-855l9)

Creates a new column of machine learning sequences from a given column whose elements can be converted to
sequences.

[`init<T>(column: MLDataColumn<T>)`](/documentation/CreateML/MLDataColumn/init(column:)-s8g5)

Creates a new column of machine learning dictionaries from a given column whose elements can be converted to
dictionaries.

### Getting the number of elements

[`var count: Int`](/documentation/CreateML/MLDataColumn/count)

The number of elements in the column.

[`var isEmpty: Bool`](/documentation/CreateML/MLDataColumn/isEmpty)

### Getting an element

[`subscript(_:)`](/documentation/CreateML/MLDataColumn/subscript(_:))

Accesses the element at the given row.

[`func element(at: Int) -> Element?`](/documentation/CreateML/MLDataColumn/element(at:))

Accesses the element at the given index.

### Appending to a data column

[`func append(contentsOf: MLDataColumn<Element>)`](/documentation/CreateML/MLDataColumn/append(contentsOf:))

Appends the elements of the given column to the end of this column.

### Duplicating a column

[`func copy() -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/copy())

Returns a new MLDataColumn by copying the original MLDataColumn

### Sorting elements to generate a column

[`func sort(byIncreasingOrder: Bool) -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/sort(byIncreasingOrder:))

Returns a new MLDataColumn containing values sorted by the specified order.

### Transforming elements to generate a column

[`func map(_:)`](/documentation/CreateML/MLDataColumn/map(_:))

Creates a new column by applying the given thread-safe transform to every non-missing element of this column.

[`func mapMissing<T>((Element?) -> T?) -> MLDataColumn<T>`](/documentation/CreateML/MLDataColumn/mapMissing(_:))

Creates a new column, potentially with missing elements, by applying the given thread-safe transform to every
element of the column, including missing elements.

### Masking elements to generate a column

[`subscript(MLDataColumn<Bool>) -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/subscript(_:)-78irf)

Creates a subset of the column by masking its elements with a column of Booleans.

[`subscript(MLUntypedColumn) -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/subscript(_:)-1n3x)

Returns a `MLDataColumn` containing only the elements for which the corresponding mask has a nonzero or
non-default value.

### Discarding elements to generate a column

[`func dropMissing() -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/dropMissing())

Creates a subset of the column by removing all elements without a value.

[`func dropDuplicates() -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/dropDuplicates())

Creates a subset of the column by removing all duplicate elements.

### Selecting elements to generate a column

[`subscript(Range<Int>) -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/subscript(_:)-pp34)

Creates a subset of the column, given a range of elements.

[`subscript<R>(R) -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/subscript(_:)-5mczv)

Creates a subset of the column, given a range expression of elements.

[`func prefix(Int) -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/prefix(_:))

Creates a subset of the column, given a number of initial elements.

[`func suffix(Int) -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/suffix(_:))

Creates a subset of the column, given a number of final elements.

### Filling in missing elements to generate a column

[`func fillMissing(with: Element) -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/fillMissing(with:))

Creates a modified copy of the column such that every missing element is replaced with the given value.

### Evaluating elements to generate a column

[`func materialize() throws -> MLDataColumn<Element>`](/documentation/CreateML/MLDataColumn/materialize())

Creates a new column by immediately evaluating any lazily applied data
processing operations stored in the column.

### Combining columns

[`static +(_:_:)`](/documentation/CreateML/MLDataColumn/+(_:_:))

Creates a column of doubles by adding the given double to each element
of the given column.

[`static -(_:_:)`](/documentation/CreateML/MLDataColumn/-(_:_:))

Creates a column of doubles by subtracting each element of the given
column from the given double.

[`static *(_:_:)`](/documentation/CreateML/MLDataColumn/*(_:_:))

Creates a column of doubles by multiplying the given double by each
element of the given column.

[`static /(_:_:)`](/documentation/CreateML/MLDataColumn/_(_:_:)-8hxiv)

Creates a column of doubles by dividing the given double by each element
of the given column.

### Combining columns to generate a column

[`static func + (MLDataColumn<Int>, MLDataColumn<Int>) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/+(_:_:)-24g38)

Creates a column of integers by adding each element in the first column
to the corresponding element in the second column.

[`static func + (MLDataColumn<Double>, MLDataColumn<Double>) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/+(_:_:)-q5bb)

Creates a column of doubles by adding each element in the first column
to the corresponding element in the second column.

[`static func - (MLDataColumn<Int>, MLDataColumn<Int>) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/-(_:_:)-11hbf)

Creates a column of integers by subtracting each element in the second
column from the corresponding element in the first column.

[`static func - (MLDataColumn<Double>, MLDataColumn<Double>) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/-(_:_:)-3mwsr)

Creates a column of doubles by subtracting each element in the second
column from the corresponding element in the first column.

[`static func * (MLDataColumn<Int>, MLDataColumn<Int>) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/*(_:_:)-40smy)

Creates a column of integers by multiplying each element in the first
column by the corresponding element in the second column.

[`static func * (MLDataColumn<Double>, MLDataColumn<Double>) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/*(_:_:)-lchb)

Creates a column of doubles by multiplying each element in the first
column by the corresponding element in the second column.

[`static func / (MLDataColumn<Int>, MLDataColumn<Int>) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/_(_:_:)-5uxby)

Creates a column of integers by dividing each element in the first
column by the corresponding element in the second column.

[`static func / (MLDataColumn<Double>, MLDataColumn<Double>) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/_(_:_:)-69vgc)

Creates a column of doubles by dividing each element in the first column
by the corresponding element in the second column.

### Combining a column with a value to generate a column

[`static func + (MLDataColumn<Int>, Int) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/+(_:_:)-7tghu)

Creates a column of integers by adding each element of the given column
to the given integer.

[`static func + (MLDataColumn<Double>, Double) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/+(_:_:)-4se2l)

Creates a column of doubles by adding each element of the given column
to the given double.

[`static func - (MLDataColumn<Int>, Int) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/-(_:_:)-2sddu)

Creates a column of integers by subtracting the given integer from each
element of the given column.

[`static func - (MLDataColumn<Double>, Double) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/-(_:_:)-9smok)

Creates a column of doubles by subtracting the given double from each
element of the given column.

[`static func * (MLDataColumn<Int>, Int) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/*(_:_:)-2zih0)

Creates a column of integers by multiplying each element of the given
column by the given integer.

[`static func * (MLDataColumn<Double>, Double) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/*(_:_:)-4ilhj)

Creates a column of doubles by multiplying each element of the given
column by the given double.

[`static func / (MLDataColumn<Int>, Int) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/_(_:_:)-3ea6t)

Creates a column of integers by dividing each element of the given
column by the given integer.

[`static func / (MLDataColumn<Double>, Double) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/_(_:_:)-8k8ao)

Creates a column of doubles by dividing each element of the given column
by the given double.

### Combining a value with a column to generate a column

[`static func + (Int, MLDataColumn<Int>) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/+(_:_:)-2zcp)

Creates a column of integers by adding the given integer to each element
of the given column.

[`static func + (Double, MLDataColumn<Double>) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/+(_:_:)-9r67n)

Creates a column of doubles by adding the given double to each element
of the given column.

[`static func - (Int, MLDataColumn<Int>) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/-(_:_:)-507l8)

Creates a column of integers by subtracting each element of the given
column from the given integer.

[`static func - (Double, MLDataColumn<Double>) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/-(_:_:)-2e7k4)

Creates a column of doubles by subtracting each element of the given
column from the given double.

[`static func * (Int, MLDataColumn<Int>) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/*(_:_:)-48xte)

Creates a column of integers by multiplying the given integer by each
element of the given column.

[`static func * (Double, MLDataColumn<Double>) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/*(_:_:)-9sysp)

Creates a column of doubles by multiplying the given double by each
element of the given column.

[`static func / (Int, MLDataColumn<Int>) -> MLDataColumn<Int>`](/documentation/CreateML/MLDataColumn/_(_:_:)-9ew9w)

Creates a column of integers by dividing the given integer by each
element of the given column.

[`static func / (Double, MLDataColumn<Double>) -> MLDataColumn<Double>`](/documentation/CreateML/MLDataColumn/_(_:_:)-121w8)

Creates a column of doubles by dividing the given double by each element
of the given column.

### Comparing columns

[`static ==(_:_:)`](/documentation/CreateML/MLDataColumn/==(_:_:))

Creates a column of Booleans by testing whether the given value is equal
to each element in the given column.

[`static !=(_:_:)`](/documentation/CreateML/MLDataColumn/!=(_:_:))

Creates a column of Booleans by testing whether the given value is not
equal to each element in the given column.

[`static <(_:_:)`](/documentation/CreateML/MLDataColumn/_(_:_:)-81qel)

Creates a column of Booleans by testing whether the given value is less
than each element in the given column.

[`static <=(_:_:)`](/documentation/CreateML/MLDataColumn/_=(_:_:)-8eq6v)

Creates a column of Booleans by testing whether the given value is less
than or equal to each element in the given column.

[`static >(_:_:)`](/documentation/CreateML/MLDataColumn/_(_:_:)-g252)

Creates a column of Booleans by testing whether the given value is
greater than each element in the given column.

[`static >=(_:_:)`](/documentation/CreateML/MLDataColumn/_=(_:_:)-64izf)

Creates a column of Booleans by testing whether the given value is
greater than or equal to each element in the given column.

### Comparing columns to generate a column of booleans

[`static func == (MLDataColumn<Element>, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/==(_:_:)-9e3tx)

Creates a column of Booleans by testing whether each element in the
first column is equal to the corresponding element in the second column.

[`static func != (MLDataColumn<Element>, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/!=(_:_:)-1vu4e)

Creates a column of Booleans by testing whether each element in the
first column is not equal to the corresponding element in the second
column.

[`static func < (MLDataColumn<Element>, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_(_:_:)-3om6w)

Creates a column of Booleans by testing whether each element in the
first column is less than the corresponding element in the second
column.

[`static func <= (MLDataColumn<Element>, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_=(_:_:)-6s5v1)

Creates a column of Booleans by testing whether each element in the
first column is less than or equal to the corresponding element in the
second column.

[`static func > (MLDataColumn<Element>, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_(_:_:)-2dym4)

Creates a column of Booleans by testing whether each element in the
first column is greater than the corresponding element in the second
column.

[`static func >= (MLDataColumn<Element>, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_=(_:_:)-4w60p)

Creates a column of Booleans by testing whether each element in the
first column is greater than or equal to the corresponding element in
the second column.

### Comparing a column with a value to generate a column of booleans

[`static func == (MLDataColumn<Element>, Element) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/==(_:_:)-7clbs)

Creates a column of Booleans by testing whether each element in the
given column is equal to the given value.

[`static func != (MLDataColumn<Element>, Element) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/!=(_:_:)-4jp0y)

Creates a column of Booleans by testing whether each element in the
given column is not equal to the given value.

[`static func < (MLDataColumn<Element>, Element) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_(_:_:)-4ujss)

Creates a column of Booleans by testing whether each element in the
given column is less than the given value.

[`static func <= (MLDataColumn<Element>, Element) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_=(_:_:)-86x3a)

Creates a column of Booleans by testing whether each element in the
given column is less than or equal to the given value.

[`static func > (MLDataColumn<Element>, Element) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_(_:_:)-ebgq)

Creates a column of Booleans by testing whether each element in the
given column is greater than the given value.

[`static func >= (MLDataColumn<Element>, Element) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_=(_:_:)-1ctuz)

Creates a column of Booleans by testing whether each element in the
given column is greater than or equal to the given value.

### Comparing a value with a column to generate a column of booleans

[`static func == (Element, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/==(_:_:)-6zz2o)

Creates a column of Booleans by testing whether the given value is equal
to each element in the given column.

[`static func != (Element, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/!=(_:_:)-4477j)

Creates a column of Booleans by testing whether the given value is not
equal to each element in the given column.

[`static func < (Element, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_(_:_:)-33lwa)

Creates a column of Booleans by testing whether the given value is less
than each element in the given column.

[`static func <= (Element, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_=(_:_:)-3fx6w)

Creates a column of Booleans by testing whether the given value is less
than or equal to each element in the given column.

[`static func > (Element, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_(_:_:)-6irjn)

Creates a column of Booleans by testing whether the given value is
greater than each element in the given column.

[`static func >= (Element, MLDataColumn<Element>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/_=(_:_:)-8e3ur)

Creates a column of Booleans by testing whether the given value is
greater than or equal to each element in the given column.

### Combining columns of booleans to generate a column of booleans

[`static func && (MLDataColumn<Bool>, MLDataColumn<Bool>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/&&(_:_:))

Creates a column of Booleans by performing a logical AND operation on
each element in the first column with the corresponding element in the
second column.

[`static func || (MLDataColumn<Bool>, MLDataColumn<Bool>) -> MLDataColumn<Bool>`](/documentation/CreateML/MLDataColumn/__(_:_:))

Creates a column of Booleans by performing a logical OR operation on
each element in the first column with the corresponding element in the
second column.

### Getting the min and max element values

[`func min()`](/documentation/CreateML/MLDataColumn/min())

Returns the element with the lowest value in a column of doubles.

[`func max()`](/documentation/CreateML/MLDataColumn/max())

Returns the element with the highest value in a column of doubles.

### Getting sum, mean, and standard deviation values

[`func sum()`](/documentation/CreateML/MLDataColumn/sum())

Returns the sum of the elements in a column of doubles.

[`func mean()`](/documentation/CreateML/MLDataColumn/mean())

Returns the arithmetic mean of the elements in a column of doubles.

[`func std()`](/documentation/CreateML/MLDataColumn/std())

Returns the standard deviation of the elements in a column of doubles.

[`func stdev()`](/documentation/CreateML/MLDataColumn/stdev())

Returns the standard deviation of the elements in a column of doubles.

### Visualizing a column

[`func show() -> any MLStreamingVisualizable`](/documentation/CreateML/MLDataColumn/show())

Provides a visualization for the data in the column.

### Getting a description of a data column

[`var description: String`](/documentation/CreateML/MLDataColumn/description)

A text representation of the column.

[`var playgroundDescription: Any`](/documentation/CreateML/MLDataColumn/playgroundDescription)

A description of the column shown in a playground.

[`var debugDescription: String`](/documentation/CreateML/MLDataColumn/debugDescription)

A text representation of the column for debugging.

### Handling data column errors

[`var isValid: Bool`](/documentation/CreateML/MLDataColumn/isValid)

A Boolean value that indicates whether the column is valid.

[`var error: (any Error)?`](/documentation/CreateML/MLDataColumn/error)

The underlying error present when the column is invalid.

### Supporting types

[`struct MLUntypedColumn`](/documentation/CreateML/MLUntypedColumn)

A column of untyped values in a data table.

### Default Implementations

[CustomDebugStringConvertible Implementations](/documentation/CreateML/MLDataColumn/CustomDebugStringConvertible-Implementations)

[CustomPlaygroundDisplayConvertible Implementations](/documentation/CreateML/MLDataColumn/CustomPlaygroundDisplayConvertible-Implementations)

[CustomStringConvertible Implementations](/documentation/CreateML/MLDataColumn/CustomStringConvertible-Implementations)

## Relationships

### Conforms To

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

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

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

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

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

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

---

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)