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:
| input | output |
|---|---|
| polars_expression | polars_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 │ ╰───┴───────╯
Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/polars_entropy.html