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

Polars · Module

df.select

Selects columns and evaluates Polars expressions to produce a new DataFrame. Inputs may be column names, iterables of names or expressions, and keyword expressions with explicit output names.

How it works

Call DataFrame.select with positional column names, lists, or expressions to construct a new DataFrame. Keyword expressions add columns whose output names come from the keyword, while strings identify columns and other non-expression values become literals.

Syntax

DataFrame.select(exprs: IntoExpr | Iterable[IntoExpr]*, **named_exprs: IntoExpr*) → DataFrame

Parameters

NameTypeDescription
exprsIntoExpr | Iterable[IntoExpr]Columns or expressions to select as positional arguments; strings are treated as column names and other non-expression inputs as literals.
named_exprsIntoExprAdditional expressions supplied by keyword; each output column is named after its keyword.

Returns

DataFrame containing the selected columns and evaluated expressions.

Key points

  • The method projects a DataFrame into a new DataFrame containing selected columns and computed expression outputs.
  • Pass one or more positional arguments to identify the columns or expressions to evaluate.
  • A list of names is a convenient form for selecting several existing columns at once.
  • Separate positional arguments provide an alternative to wrapping column names in a list.
  • Polars expressions let selection include derived values, such as arithmetic or aliases.

Common mistakes

  • A string argument refers to an existing column; pass an expression such as pl.lit(...) when you intend a literal value.
  • Keyword arguments determine the resulting column names, so the keyword can replace an expression's natural name.

Example: Selecting columns and expressions

import polars as pl

df = pl.DataFrame({"name": ["Ada", "Linus"], "age": [36, 55]})
result = df.select(
    pl.col("name"),
    (pl.col("age") + 1).alias("next_age"),
    label=pl.lit("engineer"),
)
print(result)

Selects an existing column, computes a renamed expression, and adds a literal column under a keyword name.

When to use it

Project selected columns

Reduce a wide table to the fields needed by downstream code or export.

Compute projected expressions

Create derived fields while selecting, such as adjusted values or labels.

Add named outputs

Attach constants or named expression results during projection.

Interview questions

QWhat does DataFrame.select do?

select creates a new DataFrame containing the requested columns or expression results. It accepts positional arguments, iterable inputs such as a list, and keyword expressions.

Follow-up: How would you add a constant column? Use a literal expression, for example df.select(pl.lit(1).alias("constant")).

QWhich kinds of inputs can select accept?

Positional strings are interpreted as column names, and expressions can transform or calculate values. Multiple columns can be supplied either as separate positional arguments or as a list.

Follow-up: How can an expression's output name be controlled? Alias it with .alias(...), or provide it as a keyword expression when selecting.

QHow does keyword selection affect output names?

Keyword expressions add selected outputs and use their keyword names as the resulting column names. The method returns a DataFrame.

Follow-up: What is the lazy equivalent when building an optimized query? Start with a LazyFrame and use its select method, then collect the result.

  • DataFrame.select_seq
  • polars.select
  • polars.col
  • polars.lit
  • polars.selectors

Source: polars.DataFrame.select#. Checked 2026-10-15.