PyLegendStringCollection
PyLegendStringCollection provides max, min,
join / join_strings, and distinct_value aggregations
for string columns. Inherits count and distinct_count
from PyLegendPrimitiveCollection.
count
Count the number of rows in the group.
- Returns:
The row count for each group.
- Return type:
PyLegendInteger
Examples
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
Count the number of distinct values in the group.
- Returns:
The distinct value count for each group.
- Return type:
PyLegendInteger
Examples
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
Return the single distinct string value in the group.
- Return type:
PyLegendString
Examples
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
Concatenate all strings in the group with a separator.
- Parameters:
separator (
str) – The delimiter inserted between each string.- Return type:
PyLegendString
See also
join_stringsAlias with default separator
";".
Examples
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
Alias for
join()with a default separator of";".- Return type:
PyLegendString
max
Lexicographic maximum string in the group.
- Return type:
PyLegendString
Examples
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
Lexicographic minimum string in the group.
- Return type:
PyLegendString
Examples
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