Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Function

select

Runs Polars expressions without an existing DataFrame. It returns a DataFrame by default or a LazyFrame when eager=False.

How it works

polars.select evaluates expressions without requiring an existing DataFrame. Positional inputs become selected or computed columns, while keyword expressions create columns named by their keywords; eager mode returns a DataFrame, and disabling it returns a LazyFrame.

Syntax

polars.select(exprs: IntoExpr | Iterable[IntoExpr], eager: bool = True, **named_exprs: IntoExpr) → DataFrame | LazyFrame

Parameters

NameTypeDescription
exprsIntoExpr | Iterable[IntoExpr]Column expressions supplied positionally; strings are column names and other non-expression values are literals.
eagerbool = TrueWhether to evaluate immediately. False returns a LazyFrame.
named_exprsIntoExprAdditional expressions supplied as keyword arguments; each output uses its keyword as the column name.

Returns

DataFrame when eager=True; otherwise LazyFrame.

Key points

  • Evaluates Polars expressions without first constructing a DataFrame.
  • Conceptually, it behaves like selecting from an empty DataFrame.
  • Accepts one or more positional expressions for output columns.
  • Expressions can compute derived values rather than merely project existing columns.
  • Eager evaluation is enabled by default and returns a DataFrame.
  • Keyword arguments add named output expressions.

Common mistakes

  • A string positional argument is interpreted as a column name, whereas other non-expression values are treated as literals.
  • Set eager=False when you need a lazy result rather than immediate evaluation.
  • Keyword expressions determine the output column names, potentially replacing an expression's default name.

Example: Select expressions without a DataFrame

import polars as pl

foo = pl.Series("foo", [1, 2, 3])
bar = pl.Series("bar", [3, 2, 1])
result = pl.select(
    total=foo + bar,
    difference=foo - bar,
)
print(result)

Runs expressions directly and names the resulting columns with keyword arguments.

When to use it

Expression-only calculations

Compute a result from independent Series without assembling them into a DataFrame first.

Lazy expression pipelines

Generate a column and continue with lazy transformations before execution.

Named derived columns

Assign stable names to computed outputs using keyword arguments.

Interview questions

QWhat does polars.select do, and what does eager control?

polars.select runs expressions without a context by applying them to an empty DataFrame. With the default eager=True it returns a DataFrame; eager=False produces a LazyFrame.

Follow-up: How would you defer execution? Pass eager=False, then use lazy operations such as filter and finish with collect().

QHow are positional and keyword arguments interpreted?

Positional arguments provide expressions or expression-like inputs. Strings are interpreted as column names, while other non-expression values become literals.

Follow-up: What naming behavior applies to keyword expressions? Their keywords become the output column names.

QWhen would you use polars.select instead of DataFrame.select?

The function is useful for expression-only computations, such as combining Series or generating ranges. It can also create a lazy pipeline when eager is disabled.

Follow-up: Why can a lazy result be useful? It allows subsequent operations to remain deferred until collect(), enabling a planned pipeline.

  • polars.DataFrame.select
  • polars.LazyFrame.select
  • polars.selectors

Source: polars.select — Polars documentation. Checked 2026-10-15.