count_by

count_by returns the number of rows for each group.

Syntax

Parameters

ParameterTypeDescription
colstr

The name of the output column containing the count.

by optionalUnion[str, list[str]]

The column(s) by which to group data.

  • [] returns the total count of rows in the table (default).
  • ["X"] will output the count of each group in column X.
  • ["X", "Y"] will output the count of each group designated from the X and Y columns.

Returns

A new table containing the number of rows for each group.

Examples

In this example, count_by returns the number of rows in the table and stores that in a new column, Count.

In this example, count_by returns the number of rows in the table as grouped by X and stores that in a new column, Count.

In this example, count_by returns the number of rows in the table as grouped by X and Y, and stores that in a new column Count.