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

Polars · Module

.alias

Renames the output of a Polars expression. Use it to give derived or literal expressions explicit, non-conflicting column names.

How it works

Call alias on an expression to assign the name of the column it produces. This is useful when a transformation would otherwise inherit an undesired root name, and it also lets literal expressions receive distinct names so multiple generated columns do not collide.

Syntax

Expr.alias(name: str) → Expr

Parameters

NameTypeDescription
namestrThe new name.

Returns

Expr

Key points

  • alias changes the name assigned to an expression's output.
  • The required name argument supplies the output label.
  • Use an explicit alias when a derived expression should not replace or conflict with an existing column.
  • A string transformation can be given a new output name by placing alias at the end of the expression.
  • For systematic renaming, the documentation points to name.map, name.prefix, and name.suffix.

Common mistakes

  • Literal expressions otherwise use a default name; assign distinct aliases when adding multiple literals to avoid duplicate-column errors.

Example: Rename expression outputs

import polars as pl

df = pl.DataFrame({"a": [1, 2, 3], "b": ["x", "y", "z"]})
result = df.with_columns(
    (pl.col("a") + 10).alias("a_plus_10"),
    pl.col("b").str.to_uppercase().alias("c"),
)
print(result)

Creates two derived columns and explicitly assigns their output names.

When to use it

Name derived columns

A calculation or string transformation would otherwise inherit an unsuitable column name.

Disambiguate literals

Several literal expressions are added in one projection and need distinct output labels.

Avoid output collisions

A computed expression must be prevented from overwriting an existing column.

Interview questions

QWhat does Expr.alias do?

Expr.alias returns an expression whose output name is the supplied string. In a projection such as with_columns, that name becomes the resulting column name.

Follow-up: How would you name a transformed column without using a fixed string? Use the related expression naming methods such as name.map, name.prefix, or name.suffix.

QHow do you rename a derived expression in with_columns?

Use alias after the transformation expression, for example pl.col("b").str.to_uppercase().alias("c"). The transformation is evaluated first, and the resulting expression is labeled c.

Follow-up: What problem can arise with pl.lit expressions? Multiple literals may otherwise share a default name, so give each one a unique alias.

QWhat are the parameter and return value of Expr.alias?

The method accepts one name argument, which is the new output name, and returns an Expr. It is appropriate when the desired output label is known directly.

Follow-up: When the name must be computed from the input root name, which documented alternatives should you investigate? name.map, name.prefix, and name.suffix.

  • Expr.name.map
  • Expr.name.prefix
  • Expr.name.suffix

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