---
title: "init(dictionary:)"
framework: createml
role: symbol
role_heading: Initializer
path: "createml/mldatatable/init(dictionary:)"
---

# init(dictionary:)

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

## Declaration

```swift
init(dictionary: [String : any MLDataValueConvertible]) throws
```

## Parameters

- `dictionary`: The dictionary of each column name and its associated data values.

## Discussion

Discussion Use this initializer to create a data table from an in-memory Dictionary.

For example, to create a data table as shown above, first create a dictionary. let data: [String: MLDataValueConvertible] = [     "Title": ["Alice in Wonderland", "Hamlet", "Treasure Island", "Peter Pan"],     "Author": ["Lewis Carroll", "William Shakespeare", "Robert L. Stevenson", "J. M. Barrie"],     "Pages": [124, 98, 280, 94],     "Genre": ["Fantasy", "Drama", "Adventure", "Fantasy"] ] Then, use init(dictionary:) to create a data table from the dictionary. let bookTable = try MLDataTable(dictionary: data) The keys of the dictionary become the column names, and the value of each key becomes the element(s) of the corresponding column in the data table.

## See Also

### Creating a data table

- [Creating a model from tabular data](createml/creating-a-model-from-tabular-data.md)
- [init(contentsOf:options:)](createml/mldatatable/init(contentsof:options:).md)
- [init(namedColumns:)](createml/mldatatable/init(namedcolumns:).md)
- [init()](createml/mldatatable/init().md)
- [MLDataTable.ParsingOptions](createml/mldatatable/parsingoptions.md)
