pl.Expr.map_elements
v0.18時点では❌️polars.Expr.applyという名前だったがrenameされた
docs
https://docs.pola.rs/user-guide/expressions/user-defined-python-functions/
e.g.
code:py
df.with_columns(
pl.col("a")
.map_elements(lambda x: x * 2, return_dtype=pl.Int64)
.alias("a_times_2"),
)
第2引数: return_dtype
指定しないと以下のようなwarningが出る
MapWithoutReturnDtypeWarning: Calling map_elements without specifying return_dtype can lead to unpredictable results. Specify return_dtype to silence this warning.
ちゃんと推論できるように明示的に型を指定してあげる