Spec-Zone.ru › Polars

polars.Expr.cast

Expr.cast(
    dtype: PolarsDataType | DataTypeExpr | type[Any],
    *,
    strict: bool = True,
    wrap_numerical: bool = False,
) → Expr

Cast between data types.

engine:In MemoryStreamingDistributed
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   │
└─────┴─────┘

© 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

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API