<!--
{
  "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/MLDataTable",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML11MLDataTableV"
  },
  "title" : "MLDataTable"
}
-->

# MLDataTable

A table of data for training or evaluating a machine learning model.

```
struct MLDataTable
```

## Overview

[`MLDataTable`](/documentation/CreateML/MLDataTable) is Create ML’s version of a spreadsheet in which each row
represents an entity (such as a book, in the example below) with observable
features. Each column ([`MLDataColumn`](/documentation/CreateML/MLDataColumn) or [`MLUntypedColumn`](/documentation/CreateML/MLUntypedColumn)) in the table
represents an observable feature of that entity, such as a book’s title or
author.

![A table of information about a book. Columns named “Title”, “Author”,](images/com.apple.createml/MLDataTable-1@2x.png)

In most cases you interact with columns using the typed [`MLDataColumn`](/documentation/CreateML/MLDataColumn),
especially when you need to directly access the contents of a column. You
can also interact with columns using [`MLUntypedColumn`](/documentation/CreateML/MLUntypedColumn), if the underlying
type of the column isn’t important.

After you create a data table, you can modify it with methods like
[`append(contentsOf:)`](/documentation/CreateML/MLDataTable/append(contentsOf:)),
[`addColumn(_:named:)`](/documentation/CreateML/MLDataTable/addColumn(_:named:)-kkbw), and
[`removeColumn(named:)`](/documentation/CreateML/MLDataTable/removeColumn(named:)). You can also filter or map the
contents of the data table to derive new data tables or new columns by using
various subscripts and methods like [`dropDuplicates()`](/documentation/CreateML/MLDataTable/dropDuplicates()) or
[`map(_:)`](/documentation/CreateML/MLDataTable/map(_:)-92wrj).

> Note: For a demonstration that creates and uses data tables, see
> <doc://com.apple.documentation/documentation/CreateML/creating-a-model-from-tabular-data>.

Finally, when your data table is ready, use it to train and evaluate a model
from these groups:

- Regressors like [`MLRegressor`](/documentation/CreateML/MLRegressor) and its supporting types
- Classifiers like [`MLClassifier`](/documentation/CreateML/MLClassifier) and its supporting types
- Natural language processing types like [`MLTextClassifier`](/documentation/CreateML/MLTextClassifier) and [`MLWordTagger`](/documentation/CreateML/MLWordTagger)

> Note: It’s easier to train an ``doc://com.apple.createml/documentation/CreateML/MLTextClassifier`` from folders and files
> with ``doc://com.apple.createml/documentation/CreateML/MLTextClassifier/init(trainingData:parameters:)-8n8vs`` if your data
> is ready to use, as-is. Otherwise, use a data table to prepare your data
> before training a text classifier.

## Topics

### Creating a data table

[Creating a model from tabular data](/documentation/CreateML/creating-a-model-from-tabular-data)

Train a machine learning model by using Core ML to import and manage tabular data.

[`init(contentsOf:options:)`](/documentation/CreateML/MLDataTable/init(contentsOf:options:))

Creates a data table from an imported JSON or CSV file.

[`init(dictionary:)`](/documentation/CreateML/MLDataTable/init(dictionary:))

Creates a data table from a dictionary of column names and data values.

[`init(namedColumns:)`](/documentation/CreateML/MLDataTable/init(namedColumns:))

Creates a data table from a dictionary of column names and untyped
columns.

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

Creates an empty table containing no rows or columns.

[`MLDataTable.ParsingOptions`](/documentation/CreateML/MLDataTable/ParsingOptions)

The options for parsing a comma-separated values (CSV) file into a data
table for a machine learning model.

### Getting the size of a data table

[`size`](/documentation/CreateML/MLDataTable/size)

The number of rows and columns in the data table.

### Transforming rows to generate a data column

[`map(_:)`](/documentation/CreateML/MLDataTable/map(_:))

Creates a new column by applying a given thread-safe transform to every
row in the data table.

### Adding columns

[`addColumn(_:named:)`](/documentation/CreateML/MLDataTable/addColumn(_:named:))

Adds an untyped column to the table.

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

A column of typed values in a data table.

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

A column of untyped values in a data table.

### Accessing columns

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

Retrieves or adds an untyped column with the specified name.

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

Retrieves a column with the specified name and type.

### Renaming columns

[`renameColumn(named:to:)`](/documentation/CreateML/MLDataTable/renameColumn(named:to:))

Changes the name of an existing column.

### Removing columns

[`removeColumn(named:)`](/documentation/CreateML/MLDataTable/removeColumn(named:))

Removes the column with the specified name.

### Appending to a data table

[`append(contentsOf:)`](/documentation/CreateML/MLDataTable/append(contentsOf:))

Appends the contents of the given data table to the end of this data
table.

### Generating new data tables

[Data table derivation operations](/documentation/CreateML/data-table-derivation-operations)

Create new data tables by manipulating an existing data table.

### Splitting a data table

[`randomSplitBySequence(proportion:by:on:seed:)`](/documentation/CreateML/MLDataTable/randomSplitBySequence(proportion:by:on:seed:))

[`stratifiedSplit(proportions:on:generator:)`](/documentation/CreateML/MLDataTable/stratifiedSplit(proportions:on:generator:))

Randomly split a MLDataTable into a number partitions while stratifying on a user-define label column.

[`stratifiedSplit(proportions:on:seed:)`](/documentation/CreateML/MLDataTable/stratifiedSplit(proportions:on:seed:))

Randomly split a MLDataTable into a number partitions while stratifying on a user-define label column.

[`stratifiedSplitBySequence(proportions:by:on:generator:)`](/documentation/CreateML/MLDataTable/stratifiedSplitBySequence(proportions:by:on:generator:))

Randomly split a MLDataTable into partitions on a user-define label column, while keeping rows from the same sequence in the original order.

[`stratifiedSplitBySequence(proportions:by:on:seed:)`](/documentation/CreateML/MLDataTable/stratifiedSplitBySequence(proportions:by:on:seed:))

Randomly split a MLDataTable into partitions on a user-define label column, while keeping rows from the same sequence in the original order.

### Getting information about a data table’s rows

[`MLDataTable.Row`](/documentation/CreateML/MLDataTable/Row)

A row of untyped values in a data table.

[`rows`](/documentation/CreateML/MLDataTable/rows-swift.property)

The rows of data in the table.

[`MLDataTable.Rows`](/documentation/CreateML/MLDataTable/Rows-swift.struct)

A collection of rows in a data table.

### Getting information about a data table’s columns

[`columnNames`](/documentation/CreateML/MLDataTable/columnNames-swift.property)

The names of the columns in the data table.

[`MLDataTable.ColumnNames`](/documentation/CreateML/MLDataTable/ColumnNames-swift.struct)

A collection of the names of the columns in a data table.

[`columnTypes`](/documentation/CreateML/MLDataTable/columnTypes)

The type of the data in each column.

### Saving a data table

[`write(to:)`](/documentation/CreateML/MLDataTable/write(to:))

Exports a binary file of the data table to the given directory URL.

[`write(toDirectory:)`](/documentation/CreateML/MLDataTable/write(toDirectory:))

Exports a binary file of the data table to the given directory path.

[`writeCSV(to:)`](/documentation/CreateML/MLDataTable/writeCSV(to:))

Exports a CSV file of the data table to the given directory URL.

[`writeCSV(toFile:)`](/documentation/CreateML/MLDataTable/writeCSV(toFile:))

Exports a CSV file of the data table to the given directory path.

### Visualizing a data table

[`show()`](/documentation/CreateML/MLDataTable/show())

Generates a visualization for the data in the table.

### Describing a data table

[`description`](/documentation/CreateML/MLDataTable/description)

A text representation of the data table.

[`playgroundDescription`](/documentation/CreateML/MLDataTable/playgroundDescription)

A description of the data table shown in a playground.

### Handling data table errors

[`isValid`](/documentation/CreateML/MLDataTable/isValid)

A Boolean value that indicates whether the data table is valid.

[`error`](/documentation/CreateML/MLDataTable/error)

The underlying error present when the data table is invalid.



---

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)