PyLegendStringCollection

PyLegendStringCollection provides max, min, join / join_strings, and distinct_value aggregations for string columns. Inherits count and distinct_count from PyLegendPrimitiveCollection.

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

PyLegendStringCollection.distinct_value()[source]

Return the single distinct string value in the group.

Return type:

PyLegendString

Examples

Download Interactive Notebook

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

join

PyLegendStringCollection.join(separator)[source]

Concatenate all strings in the group with a separator.

Parameters:

separator (str) – The delimiter inserted between each string.

Return type:

PyLegendString

See also

join_strings

Alias with default separator ";".

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame.groupby("Ship Name")["Ship Name"].aggregate(
    lambda x: x.join(", ")
).to_pandas().head(3)
Ship Name lambda_0(Ship Name)
0 Alfred's Futterkiste Alfred's Futterkiste, Alfred's Futterkiste, Al...
1 Alfreds Futterkiste Alfreds Futterkiste
2 Ana Trujillo Emparedados y helados Ana Trujillo Emparedados y helados, Ana Trujil...

join_strings

PyLegendStringCollection.join_strings(separator=';')[source]

Alias for join() with a default separator of ";".

Return type:

PyLegendString

max

PyLegendStringCollection.max()[source]

Lexicographic maximum string in the group.

Return type:

PyLegendString

Examples

Download Interactive Notebook

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

min

PyLegendStringCollection.min()[source]

Lexicographic minimum string in the group.

Return type:

PyLegendString

Examples

Download Interactive Notebook

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