Returns a Polars expression that assigns a label to each row based on its index, cycling through the provided expressions in a round-robin fashion.
bucketize() is the more general form of bucketize_lit(), allowing you to pass Polars expressions instead of just literal values. This enables advanced use cases such as referencing or transforming existing column values.
WarningBe cautious when using pl.lit() as the first expression
Polars will automatically infer the data type of pl.lit(). For example, pl.lit(1) is inferred as pl.Int32.
To avoid unexpected type mismatches, it’s recommended to explicitly set the desired data type using return_dtype=.
Parameters
exprs:pl.Expr | Iterable[pl.Expr]=()
One or more pl.Expr objects, which can be passed as separate arguments or as a single iterable containing multiple expressions. All expressions must resolve to the same data type.
In the list namespace, it may be easier to think of each row as an element in a list. Conceptually, you’re working with a pl.Series, where each row corresponds to one item in the list.
Alternate between a column expression and a literal value for each element: