Function element

  • Alias for an element in evaluated in an eval expression.

    Returns pl.Expr

    Example

    *
    * A horizontal rank computation by taking the elements of a list
    *
    * >df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
    * >df.withColumn(
    * ... pl.concatList(["a", "b"]).arr.eval(pl.element().rank()).alias("rank")
    * ... )
    * shape: (3, 3)
    * ┌─────┬─────┬────────────┐
    * │ abrank
    * │ --- ┆ --- ┆ --- │
    * │ i64i64list[f32] │
    * ╞═════╪═════╪════════════╡
    * │ 14 ┆ [1.0, 2.0] │
    * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
    * │ 85 ┆ [2.0, 1.0] │
    * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
    * │ 32 ┆ [2.0, 1.0] │
    * └─────┴─────┴────────────┘
    *
    * A mathematical operation on array elements
    *
    * >df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
    * >df.withColumn(
    * ... pl.concatList(["a", "b"]).arr.eval(pl.element().multiplyBy(2)).alias("a_b_doubled")
    * ... )
    * shape: (3, 3)
    * ┌─────┬─────┬─────────────┐
    * │ aba_b_doubled
    * │ --- ┆ --- ┆ --- │
    * │ i64i64list[i64] │
    * ╞═════╪═════╪═════════════╡
    * │ 14 ┆ [2, 8] │
    * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    * │ 85 ┆ [16, 10] │
    * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    * │ 32 ┆ [6, 4] │
    * └─────┴─────┴─────────────┘