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

Polars · Function

pl.col

Creates a Polars expression representing one or more DataFrame columns. Use it inside contexts such as select and with_columns to reference, transform, or expand columns.

How it works

pl.col creates a Polars expression that refers to one or more DataFrame columns. The expression is evaluated inside a context such as select or with_columns, where it can be combined with transformations, arithmetic, and other expressions.

Syntax

polars.col(name: str | PolarsDataType | Iterable[str] | Iterable[PolarsDataType], more_names: str | PolarsDataType) → Expr

Parameters

NameTypeDescription
namestr | PolarsDataType | Iterable[str] | Iterable[PolarsDataType]Column name, datatype, iterable of names or datatypes, or a regular expression identifying the column(s).
more_namesstr | PolarsDataTypeAdditional column names or datatypes supplied positionally.

Returns

Expr

Key points

  • Use pl.col to construct a column expression rather than extracting a Series immediately.
  • Although callable syntax is provided, the documentation describes col as a column-expression factory rather than technically a function.
  • The primary argument identifies columns by name or datatype.
  • Further column names or datatypes can be supplied as positional arguments.
  • Attribute lookup provides shorthand column references, such as col.foo.

Common mistakes

  • When using a regular expression to select columns, anchor it with ^ and $.
  • A wildcard selects every column, so use it deliberately when broad column expansion is intended.

Example: Select columns and compute a derived expression

import polars as pl

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

Selects the name column and builds a second expression that adds one to every age.

When to use it

Column projection

Selecting a subset of fields from a DataFrame.

Derived columns

Building arithmetic, comparison, or string transformations.

Expression expansion

Applying one operation to a group of selected columns.

Interview questions

QWhat does pl.col return, and when is it evaluated?

pl.col returns an Expr representing one or more DataFrame columns. It is not evaluated immediately; a DataFrame context such as select executes the expression.

Follow-up: How can one expression target several columns? Pass multiple names, use a regular expression, a datatype, or the wildcard selector.

QHow do you select multiple columns with pl.col?

Pass multiple column names as positional arguments, for example pl.col("x", "y"). Polars expands the expression across those selected columns in the surrounding context.

Follow-up: What alternative syntax is documented for a single column? Attribute lookup such as pl.col.foo creates the same expression as pl.col("foo").

QWhich kinds of selectors can pl.col accept?

The first argument can be a column name, datatype, iterable of names or datatypes, or a regular expression. A regular-expression selector must be anchored with ^ and $.

Follow-up: What concise selector represents every column? Use the wildcard *.

  • polars.Expr
  • polars.DataFrame.select
  • polars.DataFrame.with_columns
  • polars.col.ColumnFactory

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