Skip to content

Categories

Named categories with integer codes: a code is the index of its name.

Parameters:

Name Type Description Default
names sequence of str

Category names in code order.

required
colors sequence of str

One matplotlib color per name; None picks them at plot time.

required
mapping dict

Raw label to name, many to one.

required
other str

Name that unlisted labels fall into; appended when not listed, and always the last code.

required

decode method descriptor

decode(codes)

Name of each code; None for NaN.

encode method descriptor

encode(values)

Code of each value as float64, NaN for null. 1, 1.0 and "1" are one label. An unlisted label goes to other, else raises InvalidInput naming it and its row count.

from_json staticmethod

from_json(text)

Reads to_json output; raises InvalidInput on another class's JSON or a newer format.

from_values staticmethod

from_values(
    values,
    *,
    weights=None,
    min_share=0.0,
    mapping=None,
    other="other",
    colors=None,
)

Categories of observed values.

mapping is applied first; the distinct names are then sorted, numerically when all are integers. Names whose weighted share is below min_share are lumped into other, the last code, and recorded in mapping; other exists only when something was lumped. Integral floats are integer labels (1.0 is "1"); None and NaN are skipped. The result does not depend on row order.

lump method descriptor

lump(names, *, into='other')

New categories with names merged into into: a listed name, else other when there is none, else a new name before other. The merged names become mapping entries.

shares method descriptor

shares(codes, *, weights=None)

Weighted proportion of each code, nulls skipped.

used in