# Create DataColumn

> For the complete documentation index, see [llms.txt](https://kotlin.github.io/dataframe/llms.txt).

This section describes ways to create a [DataColumn](datacolumn.html).

API reference: [columnOf](https://kotlin.github.io/dataframe/api-docs/core/org.jetbrains.kotlinx.dataframe.api/column-of.html), [toColumn](https://kotlin.github.io/dataframe/api-docs/core/org.jetbrains.kotlinx.dataframe.api/to-column.html)

## columnOf

Returns a new column with the given elements. The column [type](datacolumn.html#properties) is deduced from the compile-time type of the elements inside. The column [name](datacolumn.html#properties) is taken from the name of the variable.

```KOTLIN
// Create ValueColumn with name 'student' and two elements of type String
val student by columnOf("Alice", "Bob")
```

To assign column name explicitly, use the `named` infix function and replace `by` with `=`.

```KOTLIN
val column = columnOf("Alice", "Bob") named "student"
```

When column elements are columns themselves, it returns a [ColumnGroup](datacolumn.html#columngroup):

```KOTLIN
val firstName by columnOf("Alice", "Bob")
val lastName by columnOf("Cooper", "Marley")

// Create ColumnGroup with two nested columns
val fullName by columnOf(firstName, lastName)
```

When column elements are [DataFrame](dataframe.html) objects, it returns a [FrameColumn](datacolumn.html#framecolumn):

```KOTLIN
val df1 = dataFrameOf("name", "age")("Alice", 20, "Bob", 25)
val df2 = dataFrameOf("name", "temp")("Charlie", 36.6)

// Create FrameColumn with two elements of type DataFrame
val frames by columnOf(df1, df2)
```

## toColumn

Converts an `Iterable` of values into a column.

```KOTLIN
listOf("Alice", "Bob").toColumn("name")
```

To compute a column type at runtime by scanning through the actual values, enable the `Infer.Type` option.

To inspect values only for nullability, enable the `Infer.Nulls` option.

```KOTLIN
val values: List<Any?> = listOf(1, 2.5)

values.toColumn("data") // type: Any?
values.toColumn("data", Infer.Type) // type: Number
values.toColumn("data", Infer.Nulls) // type: Any
```

## toColumnOf

Converts an [Iterable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-iterable/) of values into a column of a given type:

```KOTLIN
val values: List<Any?> = listOf(1, 2.5)

values.toColumnOf<Number?>("data") // type: Number?
```

