PyLegendFloatCollection

PyLegendFloatCollection overrides max, min, sum, and distinct_value to return PyLegendFloat instead of PyLegendNumber. All other aggregation methods are inherited from PyLegendNumberCollection.

average

PyLegendNumberCollection.average()[source]

Arithmetic mean of the values in the group.

Return type:

PyLegendFloat

See also

mean

Alias for average.

Examples

Download Interactive Notebook

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

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

PyLegendFloatCollection.distinct_value()[source]

Return the single distinct float value in the group.

Return type:

PyLegendFloat

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_float"] = frame["Order Id"] * 1.0
frame.groupby("Order Id")["id_float"].aggregate(
    lambda x: x.distinct_value()
).to_pandas().head(3)
Order Id id_float
0 10248 10248.0
1 10249 10249.0
2 10250 10250.0

max

PyLegendFloatCollection.max()[source]

Maximum float value in the group.

Return type:

PyLegendFloat

Examples

Download Interactive Notebook

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

mean

PyLegendNumberCollection.mean()[source]

Alias for average().

Return type:

PyLegendFloat

median

PyLegendNumberCollection.median()[source]

Median of the values in the group.

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

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

min

PyLegendFloatCollection.min()[source]

Minimum float value in the group.

Return type:

PyLegendFloat

Examples

Download Interactive Notebook

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

percentile

PyLegendNumberCollection.percentile(percentile, ascending=True, continuous=True)[source]

Compute a percentile of the values in the group.

Parameters:
  • percentile (float) – The percentile to compute, between 0 and 1.

  • ascending (bool) – If True, values are sorted in ascending order before computing the percentile.

  • continuous (bool) – If True, use continuous (interpolated) percentile (PERCENTILE_CONT). If False, use discrete (PERCENTILE_DISC).

Return type:

PyLegendNumber

Examples

Download Interactive Notebook

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

row_mapper

PyLegendNumberCollection.row_mapper(other)[source]

Pair this collection with another numeric value for bivariate aggregations (correlation, covariance, weighted average).

Parameters:

other (Union[int, float, PyLegendInteger, PyLegendFloat, PyLegendDecimal, PyLegendNumber, PyLegendNumberCollection]) – The second numeric operand.

Returns:

A paired collection supporting corr, covar_sample, covar_population, and wavg_legend_ext.

Return type:

PyLegendNumberPairCollection

std_dev

PyLegendNumberCollection.std_dev()[source]

Alias for std_dev_sample().

Return type:

PyLegendNumber

std_dev_population

PyLegendNumberCollection.std_dev_population()[source]

Population standard deviation of the values in the group.

Return type:

PyLegendNumber

See also

std_dev_sample

Sample standard deviation.

Examples

Download Interactive Notebook

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

std_dev_sample

PyLegendNumberCollection.std_dev_sample()[source]

Sample standard deviation of the values in the group.

Return type:

PyLegendNumber

See also

std_dev

Alias for std_dev_sample.

std_dev_population

Population standard deviation.

Examples

Download Interactive Notebook

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

sum

PyLegendFloatCollection.sum()[source]

Sum of the float values in the group.

Return type:

PyLegendFloat

Examples

Download Interactive Notebook

import pylegend
frame = pylegend.samples.pandas_api.northwind_orders_frame()
frame["id_float"] = frame["Order Id"] * 1.0
frame.groupby("Ship Name")["id_float"].aggregate(
    lambda x: x.sum()
).to_pandas().head(3)
Ship Name id_float
0 Alfred's Futterkiste 54192.0
1 Alfreds Futterkiste 10643.0
2 Ana Trujillo Emparedados y helados 42618.0

variance

PyLegendNumberCollection.variance()[source]

Alias for variance_sample().

Return type:

PyLegendNumber

variance_population

PyLegendNumberCollection.variance_population()[source]

Population variance of the values in the group.

Return type:

PyLegendNumber

See also

variance_sample

Sample variance.

Examples

Download Interactive Notebook

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

variance_sample

PyLegendNumberCollection.variance_sample()[source]

Sample variance of the values in the group.

Return type:

PyLegendNumber

See also

variance

Alias for variance_sample.

variance_population

Population variance.

Examples

Download Interactive Notebook

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