polars.Expr.cast
-
Cast between data types.
- Parameters:
-
- dtype
-
DataType to cast to.
- strict
-
Raise if cast is invalid on rows after predicates are pushed down. If
False, invalid casts will produce null values. - wrap_numerical
-
If True numeric casts wrap overflowing values instead of marking the cast as invalid.
Examples
>>> df = pl.DataFrame( ... { ... "a": [1, 2, 3], ... "b": ["4", "5", "6"], ... } ... ) >>> df.with_columns( ... pl.col("a").cast(pl.Float64), ... pl.col("b").cast(pl.Int32), ... ) shape: (3, 2) ┌─────┬─────┐ │ a ┆ b │ │ --- ┆ --- │ │ f64 ┆ i32 │ ╞═════╪═════╡ │ 1.0 ┆ 4 │ │ 2.0 ┆ 5 │ │ 3.0 ┆ 6 │ └─────┴─────┘
Expr.cast(
dtype: PolarsDataType | DataTypeExpr | type[Any],
*,
strict: bool = True,
wrap_numerical: bool = False,
) → Expr
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.cast.html