polars cast
for dataframe
Cast a column to a different dtype.
This command requires a plugin
The polars cast
command resides in the polars
plugin. To use this command, you must install and register nu_plugin_polars
. See the Plugins chapter in the book for more information.
Signature
> polars cast {flags} (dtype) (column)
Parameters
dtype
: The dtype to cast the column tocolumn
: The column to cast. Required when used with a dataframe.
Input/output types:
input | output |
---|---|
any | any |
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