Expression-only calculations
Compute a result from independent Series without assembling them into a DataFrame first.
Polars · Function
Runs Polars expressions without an existing DataFrame. It returns a DataFrame by default or a LazyFrame when eager=False.
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.
polars.select(exprs: IntoExpr | Iterable[IntoExpr], eager: bool = True, **named_exprs: IntoExpr) → DataFrame | LazyFrame| Name | Type | Description |
|---|---|---|
exprs | IntoExpr | Iterable[IntoExpr] | Column expressions supplied positionally; strings are column names and other non-expression values are literals. |
eager | bool = True | Whether to evaluate immediately. False returns a LazyFrame. |
named_exprs | IntoExpr | Additional expressions supplied as keyword arguments; each output uses its keyword as the column name. |
DataFrame when eager=True; otherwise LazyFrame.
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.
Compute a result from independent Series without assembling them into a DataFrame first.
Generate a column and continue with lazy transformations before execution.
Assign stable names to computed outputs using keyword arguments.
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().
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.
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.selectpolars.LazyFrame.selectpolars.selectors