# chunked

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

Splits a [DataFrame](dataframe.html) into consecutive sub-dataframes (chunks) and returns them as a [FrameColumn](datacolumn.html#framecolumn). Chunks are formed in order and do not overlap.

API reference: [chunked](https://kotlin.github.io/dataframe/api-docs/core/org.jetbrains.kotlinx.dataframe.api/chunked.html)

Each chunk contains at most the specified number of rows. The resulting `FrameColumn`’s name can be customized; by default, it is "groups."

`DataFrame` can be split into chunks in two ways:

* By fixed size: split into chunks of up to the given size.

* By start indices: split using custom zero-based start indices for each chunk; each chunk ends right before the next start index or the end of the DataFrame.

```KOTLIN
df.chunked(size: Int, name: String)
df.chunked(startIndices: List<Int>, name: String)
```

If called on a [DataColumn](datacolumn.html), groups consecutive values of this column into lists of at most the given size and returns them as a [ValueColumn](datacolumn.html#valuecolumn) of lists.

If called on a [ColumnGroup](datacolumn.html#columngroup) (or on a [DataColumn](datacolumn.html) of rows), splits it into a [FrameColumn](datacolumn.html#framecolumn) of sub-dataframes with at most the given number of rows in each chunk. The resulting [FrameColumn](datacolumn.html#framecolumn) inherits the name of the group (or the column of rows).

```KOTLIN
column.chunked(size: Int)
columnGroup.chunked(size: Int)
```

## Examples

```KOTLIN
df
```

[Embedded content](./resources/notebook_test_chunked_1.html)

Fixed size chunks:

```KOTLIN
df.chunked(size = 2)
```

[Embedded content](./resources/notebook_test_chunked_2.html)

Custom start indices:

```KOTLIN
df.chunked(startIndices = listOf(0, 1, 3), name = "segments")
```

[Embedded content](./resources/notebook_test_chunked_3.html)

