Polars 2 · Expressions, grouping and joins
Conditional columns
Set a value by condition, like CASE WHEN in SQL.
df.with_columns(
pl.when(pl.col("age") >= 40).then(pl.lit("senior")).otherwise(pl.lit("junior")).alias("level")
)
Official Polars 2 documentation
More expressions, grouping and joins commands
- Group and aggregate
- Join two DataFrames
- Handle missing values
- Work with strings
- Work with dates
- Window functions
All expressions, grouping and joins commands · Polars 2 cheatsheet