Generic Structure

MLDataColumn

A column of typed values in a data table.

Declaration

struct MLDataColumn<Element> where Element : MLDataValueConvertible

Overview

A column is a homogenous collection of data values, similar to an Array. Columns are the main components of an MLDataTable and are designed to efficiently scale with large data sets.

Typically you use MLDataColumn, the typed equivalent to MLUntypedColumn, to work directly with the column’s element type. A data column has extra math and statistics functionality when its element type is Int or Double.

Topics

Creating a Data Column

init(repeating: Element, count: Int)

Creates a new column with a repeating element.

init<S>(S)

Creates a new column from a given sequence of elements.

Creating a Data Column by Converting Another Column

func map<T>(to: T.Type) -> MLDataColumn<T>

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

init<T>(column: MLDataColumn<T>)

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

init<T>(column: MLDataColumn<T>)

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>)

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

init<T>(column: MLDataColumn<T>)

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>)

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

init<T>(column: MLDataColumn<T>)

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>)

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

init<T>(column: MLDataColumn<T>)

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

The number of elements in the column.

Getting an Element

subscript(Int) -> Element

Accesses the element at the given row.

func element(at: Int) -> Element?

Accesses the element at the given index.

Appending to a Data Column

func append(contentsOf: MLDataColumn<Element>)

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

Transforming Elements to Generate a Column

func map<T>((Element) -> T) -> MLDataColumn<T>

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

func map<T>((Element) -> T?) -> MLDataColumn<T>

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

func mapMissing<T>((Element?) -> T?) -> MLDataColumn<T>

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>

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

Discarding Elements to Generate a Column

func dropMissing() -> MLDataColumn<Element>

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

func dropDuplicates() -> MLDataColumn<Element>

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

Selecting Elements to Generate a Column

subscript(Range<Int>) -> MLDataColumn<Element>

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

subscript<R>(R) -> MLDataColumn<Element>

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

func prefix(Int) -> MLDataColumn<Element>

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

func suffix(Int) -> MLDataColumn<Element>

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>

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() -> MLDataColumn<Element>

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

Combining Columns to Generate a Column

static func + (MLDataColumn<Int>, MLDataColumn<Int>) -> MLDataColumn<Int>

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>

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>

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>

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>

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>

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>

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>

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>

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

static func + (MLDataColumn<Double>, Double) -> MLDataColumn<Double>

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

static func - (MLDataColumn<Int>, Int) -> MLDataColumn<Int>

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

static func - (MLDataColumn<Double>, Double) -> MLDataColumn<Double>

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

static func * (MLDataColumn<Int>, Int) -> MLDataColumn<Int>

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

static func * (MLDataColumn<Double>, Double) -> MLDataColumn<Double>

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

static func / (MLDataColumn<Int>, Int) -> MLDataColumn<Int>

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

static func / (MLDataColumn<Double>, Double) -> MLDataColumn<Double>

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>

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

static func + (Double, MLDataColumn<Double>) -> MLDataColumn<Double>

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

static func - (Int, MLDataColumn<Int>) -> MLDataColumn<Int>

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

static func - (Double, MLDataColumn<Double>) -> MLDataColumn<Double>

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

static func * (Int, MLDataColumn<Int>) -> MLDataColumn<Int>

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

static func * (Double, MLDataColumn<Double>) -> MLDataColumn<Double>

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

static func / (Int, MLDataColumn<Int>) -> MLDataColumn<Int>

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

static func / (Double, MLDataColumn<Double>) -> MLDataColumn<Double>

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

Comparing Columns to Generate a Column of Booleans

static func == (MLDataColumn<Element>, MLDataColumn<Element>) -> MLDataColumn<Bool>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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() -> Int?

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

func min() -> Double?

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

func max() -> Int?

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

func max() -> Double?

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

Getting Sum, Mean, and Standard Deviation Values

func sum() -> Int?

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

func sum() -> Double?

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

func mean() -> Double?

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

func mean() -> Double?

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

func std() -> Double?

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

Deprecated
func stdev() -> Double?

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

func std() -> Double?

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

Deprecated

Visualizing a Column

func show() -> MLStreamingVisualizable

Provides a visualization for the data in the column.

protocol MLStreamingVisualizable

Provides a series of visualizations of a machine learning type.

Beta

Getting a Description of a Data Column

var description: String

A text representation of the column.

var playgroundDescription: Any

A description of the column shown in a playground.

var debugDescription: String

A text representation of the column for debugging.

Handling Data Column Errors

var isValid: Bool

A Boolean value indicating whether the column is valid.

var error: Error?

The underlying error present when the column is invalid.

Instance Properties

Instance Methods

func stdev() -> Double?

See Also

Adding Columns

func addColumn(MLUntypedColumn, named: String)

Adds an untyped column to the table.

struct MLUntypedColumn

A column of untyped values in a data table.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software