polars math log

For dataframe.

Compute the element-wise logarithm of a column expression.

warning This command requires a plugin The polars math log 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.

Command Type

plugin

Signature

> polars math log {flags} (base)

Parameters

  • base: Logarithm base (default: e, the natural logarithm).

Input/output types:

input output
polars_expression polars_expression
polars_selector polars_expression

Examples

Compute the base-2 logarithm of a column

> [[a]; [0] [1] [2] [4] [8] [16]] |
    polars into-df |
    polars select (polars col a | polars math log 2 | polars as a_base2) |
    polars collect
╭───┬─────────╮
│ # │ a_base2 │
├───┼─────────┤
│ 0 │    -inf │
│ 1 │    0.00 │
│ 2 │    1.00 │
│ 3 │    2.00 │
│ 4 │    3.00 │
│ 5 │    4.00 │
╰───┴─────────╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.