Skip to content

Get the first n rows.

Source code

Description

Get the first n rows.

Usage

<DataFrame>$head(n = 5L)

DataFrame_limit(n = 5L)

Arguments

n Number of rows to return. If a negative value is passed, return all rows except the last abs(n).

Details

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

Value

A DataFrame

Examples

library("polars")

df = pl$DataFrame(foo = 1:5, bar = 6:10, ham = letters[1:5])

df$head(3)
#> shape: (3, 3)
#> ┌─────┬─────┬─────┐
#> │ foo ┆ bar ┆ ham │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ i32 ┆ str │
#> ╞═════╪═════╪═════╡
#> │ 1   ┆ 6   ┆ a   │
#> │ 2   ┆ 7   ┆ b   │
#> │ 3   ┆ 8   ┆ c   │
#> └─────┴─────┴─────┘
# Pass a negative value to get all rows except the last `abs(n)`.
df$head(-3)
#> shape: (2, 3)
#> ┌─────┬─────┬─────┐
#> │ foo ┆ bar ┆ ham │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ i32 ┆ str │
#> ╞═════╪═════╪═════╡
#> │ 1   ┆ 6   ┆ a   │
#> │ 2   ┆ 7   ┆ b   │
#> └─────┴─────┴─────┘