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
    • Deprecated
    • Env
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

polars pivot for dataframe

Pivot a DataFrame from wide to long format.

This command requires a plugin

The polars pivot 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 pivot {flags}

Flags

  • --on, -o {list<string>}: column names for pivoting
  • --index, -i {list<string>}: column names for indexes
  • --values, -v {list<string>}: column names used as value columns
  • --aggregate, -a {string}: Aggregation to apply when pivoting. The following are supported: first, sum, min, max, mean, median, count, last
  • --sort, -s: Sort columns
  • --streamable, -t: Whether or not to use the polars streaming engine. Only valid for lazy dataframes

Input/output types:

inputoutput
anyany

Examples

Perform a pivot in order to show individuals test score by subject

> [[name subject test_1 test_2]; [Cady maths 98 100] [Cady physics 99 100] [Karen maths 61 60] [Karen physics 58 60]] | polars into-df |  polars pivot --on [subject] --index [name] --values [test_1]
╭───┬───────┬───────┬─────────╮
│ # │ name  │ maths │ physics │
├───┼───────┼───────┼─────────┤
│ 0 │ Cady  │    98 │      99 │
│ 1 │ Karen │    61 │      58 │
╰───┴───────┴───────┴─────────╯
Edit this page on GitHub
Contributors: Justin Ma, sholderbach