Skip to content

ValueCount(column, measure=Measure.COUNT, weights=None) Source

The column whose values are counted, and how, used by Table.count_values.

Added in version 0.2.0

Parameters:

  • column (str)

    The name of the column.

  • measure (Measure, default: Measure.COUNT)

    The number of rows holding each value by default, or with Measure.RATIO their fraction of every row.

  • weights (str | None, default: None)

    A column of numbers telling how many units each row stands for, such as the weights of a survey. Each value then counts the sum of the weights of its rows, as decimals, in weighted_count or weighted_ratio. A row without weight is left out, and a negative weight raises InvalidWeightError. Every row counts once when omitted.

Raises:

Examples:

import numdaplot as ndp

answers = ndp.Table.from_arrays({"sex": ndp.Array.from_list([2.0, 1.0, 2.0, None])})
answers.count_values(ndp.ValueCount(column="sex", measure=ndp.Measure.RATIO))
#       sex value_ratio
#   FLOAT64     FLOAT64
# 0     2.0        0.50
# 1     1.0        0.25
# 2     NaN        0.25
weights = ndp.Array.from_list([100.0, 300.0, 100.0, None])
weighted_answers = answers.add_column(ndp.NewColumn(name="weight", values=weights))
weighted_answers.count_values(ndp.ValueCount(column="sex", measure=ndp.Measure.RATIO, weights="weight"))
#       sex weighted_ratio
#   FLOAT64        FLOAT64
# 0     1.0            0.6
# 1     2.0            0.4