PyLegendBooleanCollection

PyLegendBooleanCollection is used when a boolean column participates in an aggregation context (e.g. inside groupby().agg()). It inherits count and distinct_count from PyLegendPrimitiveCollection and adds distinct_value.

count

PyLegendPrimitiveCollection.count()[source]

Count the number of rows in the group.

Returns:

The row count for each group.

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame.groupby("Ship Name")["Order Id"].aggregate(
    lambda x: x.count()
).to_pandas().head(3)
Ship Name Order Id
0 Alfred's Futterkiste 5
1 Alfreds Futterkiste 1
2 Ana Trujillo Emparedados y helados 4

distinct_count

PyLegendPrimitiveCollection.distinct_count()[source]

Count the number of distinct values in the group.

Returns:

The distinct value count for each group.

Return type:

PyLegendInteger

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame.groupby("Ship Name")["Order Id"].aggregate(
    lambda x: x.distinct_count()
).to_pandas().head(3)
Ship Name Order Id
0 Alfred's Futterkiste 5
1 Alfreds Futterkiste 1
2 Ana Trujillo Emparedados y helados 4

distinct_value

PyLegendBooleanCollection.distinct_value()[source]

Return the single distinct value in the group.

Raises an error at query time if the group contains more than one distinct value.

Returns:

The unique boolean value for each group.

Return type:

PyLegendBoolean

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["is_large"] = frame["Order Id"] > 11000
frame.groupby("Ship Name")["is_large"].aggregate(
    lambda x: x.distinct_value()
).to_pandas().head(3)
Ship Name is_large
0 Alfred's Futterkiste <NA>
1 Alfreds Futterkiste False
2 Ana Trujillo Emparedados y helados False