Skip to content

ValueCounts

Base classes

Name Children Inherits
CallOp
datacook.engine.ops.base
An op that is one pandas call.

⋔ Inheritance diagram

graph TD
  955962183["stats.ValueCounts"]
  3484306131["base.CallOp"]
  1539482213["base.Op"]
  2751680898["builtins.object"]
  3484306131 --> 955962183
  1539482213 --> 3484306131
  2751680898 --> 1539482213

🛈 DocStrings

Bases: CallOp

Source code in src/datacook/engine/ops/stats.py
class ValueCounts(base.CallOp):
    id = "value_counts"
    title = _("Value counts")
    description = _(
        "Count the rows per value (or per combination of values) of columns: a new table"
        " with the values and a count (or share) column."
    )
    category = categories.STATS
    icon = "mdi.counter"
    method = "value_counts"
    then = ".reset_index()"

    class Params(base.Params):
        subset: list[str] | None = _subset()
        normalize: bool = Field(False, title=N_("Shares instead of counts"))
        sort: bool = Field(True, title=N_("Sort by count"))
        ascending: bool = Field(False, title=N_("Ascending"))
        dropna: bool = Field(True, title=N_("Ignore missing values"))

    @classmethod
    def finish(cls, params: Any, result: Any) -> Any:
        return result.reset_index()

:fa-brands-github: Show source on GitHub