polars cast for dataframe
Cast a column to a different dtype.
Signature
> polars cast {flags} (dtype) (column)
Parameters
-
dtype: The dtype to cast the column to. -
column: The column to cast. Required when used with a dataframe.
Input/output types:
| input | output |
|---|---|
| polars_expression | polars_expression |
| polars_dataframe | polars_dataframe |
| polars_lazyframe | polars_lazyframe |
Examples
Cast a column in a dataframe to a different dtype
> [[a b]; [1 2] [3 4]] | polars into-df | polars cast u8 a | polars schema ╭───┬─────╮ │ a │ u8 │ │ b │ i64 │ ╰───┴─────╯
Cast a column in a lazy dataframe to a different dtype
> [[a b]; [1 2] [3 4]] | polars into-df | polars into-lazy | polars cast u8 a | polars schema ╭───┬─────╮ │ a │ u8 │ │ b │ i64 │ ╰───┴─────╯
Cast a column in a expression to a different dtype
> [[a b]; [1 2] [1 4]] | polars into-df | polars group-by a | polars agg [ (polars col b | polars cast u8 | polars min | polars as "b_min") ] | polars schema
Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/polars_cast.html