chunked
Splits a DataFrame
into consecutive sub-dataframes (chunks) and returns them as a FrameColumn
. Chunks are formed in order and do not overlap.
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.
df.chunked(size: Int, name: String)
df.chunked(startIndices: List<Int>, name: String)
Examples
df
Fixed size chunks:
df.chunked(size = 2)
Custom start indices:
df.chunked(startIndices = listOf(0, 1, 3), name = "segments")
18 September 2025