Skip to content

Get the first n rows.

Source code

Description

A shortcut for $slice(0, n). Consider using the $fetch() method if you want to test your query. The $fetch() operation will load the first n rows at the scan level, whereas $head() is applied at the end.

Usage

<LazyFrame>$head(n = 5L)

Arguments

n Number of rows to return.

Details

$limit() is an alias for $head().

Value

A new LazyFrame object with applied filter.

Examples

library("polars")

lf = pl$LazyFrame(a = 1:6, b = 7:12)

lf$head()$collect()
#> shape: (5, 2)
#> ┌─────┬─────┐
#> │ a   ┆ b   │
#> │ --- ┆ --- │
#> │ i32 ┆ i32 │
#> ╞═════╪═════╡
#> │ 1   ┆ 7   │
#> │ 2   ┆ 8   │
#> │ 3   ┆ 9   │
#> │ 4   ┆ 10  │
#> │ 5   ┆ 11  │
#> └─────┴─────┘
lf$head(2)$collect()
#> shape: (2, 2)
#> ┌─────┬─────┐
#> │ a   ┆ b   │
#> │ --- ┆ --- │
#> │ i32 ┆ i32 │
#> ╞═════╪═════╡
#> │ 1   ┆ 7   │
#> │ 2   ┆ 8   │
#> └─────┴─────┘