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 entropy for dataframe

Compute the entropy as `-sum(pk * log(pk))` where `pk` are discrete probabilities.

Signature

> polars entropy {flags}

Flags

  • --base {float}: Given base, defaults to e.
  • --normalize {bool}: Normalize pk if it doesn’t sum to 1. Default to true.

Input/output types:

inputoutput
polars_expressionpolars_expression

Examples

Compute the entropy of a column expression

> [[a]; [1] [2] [3]] | polars into-df | polars select (polars col a | polars entropy --base 2) | polars collect
╭───┬──────╮
│ # │  a   │
├───┼──────┤
│ 0 │ 1.46 │
╰───┴──────╯

Compute the entropy of a column expression without normalization

> [[a]; [1] [2] [3]] | polars into-df | polars select (polars col a | polars entropy --base 2 --normalize false) | polars collect
╭───┬───────╮
│ # │   a   │
├───┼───────┤
│ 0 │ -6.75 │
╰───┴───────╯