Method: Polars::Functions#nth

Defined in:
lib/polars/functions/lazy.rb

#nth(*indices) ⇒ Expr

Get the nth column(s) of the context.

Examples:

df = Polars::DataFrame.new(
  {
    "a" => [1, 8, 3],
    "b" => [4, 5, 2],
    "c" => ["foo", "bar", "baz"]
  }
)
df.select(Polars.nth(1))
# =>
# shape: (3, 1)
# ┌─────┐
# │ b   │
# │ --- │
# │ i64 │
# ╞═════╡
# │ 4   │
# │ 5   │
# │ 2   │
# └─────┘
df.select(Polars.nth(2, 0))
# =>
# shape: (3, 2)
# ┌─────┬─────┐
# │ c   ┆ a   │
# │ --- ┆ --- │
# │ str ┆ i64 │
# ╞═════╪═════╡
# │ foo ┆ 1   │
# │ bar ┆ 8   │
# │ baz ┆ 3   │
# └─────┴─────┘

Parameters:

  • indices (Array)

    One or more indices representing the columns to retrieve.

Returns:

[View source]

568
569
570
571
572
573
574
# File 'lib/polars/functions/lazy.rb', line 568

def nth(*indices)
  if indices.length == 1 && indices[0].is_a?(Array)
    indices = indices[0]
  end

  Utils.wrap_expr(Plr.index_cols(indices))
end