Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

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 to
  • column: The column to cast. Required when used with a dataframe.

Input/output types:

inputoutput
anyany

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