LazyFrame#

LazyFrame Frame#

class TdPolarsType#

Internal private Functions.

alias of TypeVar(‘TdPolarsType’, ~tabsdata.TdLazyFrame, ~polars.series.series.Series, ~tabsdata.TdExpr)

check_polars_api()[source]#

Check polars API.

get_class_methods(cls) List[str][source]#
get_missing_methods()[source]#

LazyFrame GroupBy#

class TdLazyGroupBy(lgb: LazyGroupBy | TdLazyGroupBy)[source]#

Bases: object

agg(*aggs: td_expr.IntoTdExpr | Iterable[td_expr.IntoTdExpr], **named_aggs: td_expr.IntoTdExpr) td_frame.TdLazyFrame[source]#

Aggregation expressions for the group by column(s).

Parameters:

*aggs – Aggregation operations.

Examples:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ A    ┆ 1    │
│ B    ┆ 2    │
│ A    ┆ 3    │
│ B    ┆ 0    │
│ C    ┆ 5    │
│ null ┆ 6    │
│ C    ┆ null │
└──────┴──────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b").sum().alias("agg")).collect()
>>>
┌──────┬─────┐
│ a    ┆ agg │
│ ---  ┆ --- │
│ str  ┆ i64 │
╞══════╪═════╡
│ A    ┆ 4   │
│ C    ┆ 5   │
│ null ┆ 6   │
│ B    ┆ 2   │
└──────┴─────┘
count() TdLazyFrame[source]#
len() TdLazyFrame[source]#

Aggregation operation that counts the rows in the group.

Examples:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┬──────┐
│ ss   ┆ u    ┆ ff   │
│ ---  ┆ ---  ┆ ---  │
│ str  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ A    ┆ 1    ┆ 1.1  │
│ B    ┆ 0    ┆ 0.0  │
│ A    ┆ 2    ┆ 2.2  │
│ B    ┆ 3    ┆ 3.3  │
│ B    ┆ 4    ┆ 4.4  │
│ C    ┆ 5    ┆ -1.1 │
│ C    ┆ 6    ┆ -2.2 │
│ C    ┆ 7    ┆ -3.3 │
│ D    ┆ 8    ┆ inf  │
│ F    ┆ 9    ┆ NaN  │
│ null ┆ null ┆ null │
└──────┴──────┴──────┘
>>>
>>> tf.group_by(td.col("ss")).len()
>>>
┌──────┬─────┐
│ ss   ┆ len │
│ ---  ┆ --- │
│ str  ┆ u32 │
╞══════╪═════╡
│ null ┆ 1   │
│ B    ┆ 3   │
│ F    ┆ 1   │
│ C    ┆ 3   │
│ A    ┆ 2   │
│ D    ┆ 1   │
└──────┴─────┘
max() TdLazyFrame[source]#

Aggregation operation that computes the maximum value in the group for of all the non group by columns.

Examples:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┬──────┐
│ ss   ┆ u    ┆ ff   │
│ ---  ┆ ---  ┆ ---  │
│ str  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ A    ┆ 1    ┆ 1.1  │
│ B    ┆ 0    ┆ 0.0  │
│ A    ┆ 2    ┆ 2.2  │
│ B    ┆ 3    ┆ 3.3  │
│ B    ┆ 4    ┆ 4.4  │
│ C    ┆ 5    ┆ -1.1 │
│ C    ┆ 6    ┆ -2.2 │
│ C    ┆ 7    ┆ -3.3 │
│ D    ┆ 8    ┆ inf  │
│ F    ┆ 9    ┆ NaN  │
│ null ┆ null ┆ null │
└──────┴──────┴──────┘
>>>
>>> tf.group_by("ss").max()
>>>
┌──────┬──────┬──────┐
│ ss   ┆ u    ┆ ff   │
│ ---  ┆ ---  ┆ ---  │
│ str  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ null ┆ null ┆ null │
│ A    ┆ 2    ┆ 2.2  │
│ B    ┆ 4    ┆ 4.4  │
│ C    ┆ 7    ┆ -1.1 │
│ D    ┆ 8    ┆ inf  │
│ F    ┆ 9    ┆ NaN  │
└──────┴──────┴──────┘
mean() TdLazyFrame[source]#

Aggregation operation that computes the mean value in the group for of all the non group by columns.

Examples:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┬──────┐
│ ss   ┆ u    ┆ ff   │
│ ---  ┆ ---  ┆ ---  │
│ str  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ A    ┆ 1    ┆ 1.1  │
│ B    ┆ 0    ┆ 0.0  │
│ A    ┆ 2    ┆ 2.2  │
│ B    ┆ 3    ┆ 3.3  │
│ B    ┆ 4    ┆ 4.4  │
│ C    ┆ 5    ┆ -1.1 │
│ C    ┆ 6    ┆ -2.2 │
│ C    ┆ 7    ┆ -3.3 │
│ D    ┆ 8    ┆ inf  │
│ F    ┆ 9    ┆ NaN  │
│ null ┆ null ┆ null │
└──────┴──────┴──────┘
>>>
>>> tf.group_by("ss").mean()
>>>
┌──────┬──────────┬──────────┐
│ ss   ┆ u        ┆ ff       │
│ ---  ┆ ---      ┆ ---      │
│ str  ┆ f64      ┆ f64      │
╞══════╪══════════╪══════════╡
│ null ┆ null     ┆ null     │
│ A    ┆ 1.5      ┆ 1.65     │
│ B    ┆ 2.333333 ┆ 2.566667 │
│ C    ┆ 6.0      ┆ -2.2     │
│ D    ┆ 8.0      ┆ inf      │
│ F    ┆ 9.0      ┆ NaN      │
└──────┴──────────┴──────────┘
median() TdLazyFrame[source]#

Aggregation operation that computes the median value in the group for of all the non group by columns.

Examples:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┬──────┐
│ ss   ┆ u    ┆ ff   │
│ ---  ┆ ---  ┆ ---  │
│ str  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ A    ┆ 1    ┆ 1.1  │
│ B    ┆ 0    ┆ 0.0  │
│ A    ┆ 2    ┆ 2.2  │
│ B    ┆ 3    ┆ 3.3  │
│ B    ┆ 4    ┆ 4.4  │
│ C    ┆ 5    ┆ -1.1 │
│ C    ┆ 6    ┆ -2.2 │
│ C    ┆ 7    ┆ -3.3 │
│ D    ┆ 8    ┆ inf  │
│ F    ┆ 9    ┆ NaN  │
│ null ┆ null ┆ null │
└──────┴──────┴──────┘
>>>
>>> tf.group_by("ss").median()
>>>
┌──────┬──────┬──────┐
│ ss   ┆ u    ┆ ff   │
│ ---  ┆ ---  ┆ ---  │
│ str  ┆ f64  ┆ f64  │
╞══════╪══════╪══════╡
│ null ┆ null ┆ null │
│ A    ┆ 1.5  ┆ 1.65 │
│ B    ┆ 3.0  ┆ 3.3  │
│ C    ┆ 6.0  ┆ -2.2 │
│ D    ┆ 8.0  ┆ inf  │
│ F    ┆ 9.0  ┆ NaN  │
└──────┴──────┴──────┘
min() TdLazyFrame[source]#

Aggregation operation that computes the minimum value in the group for of all the non group by columns.

Examples:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┬──────┐
│ ss   ┆ u    ┆ ff   │
│ ---  ┆ ---  ┆ ---  │
│ str  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ A    ┆ 1    ┆ 1.1  │
│ B    ┆ 0    ┆ 0.0  │
│ A    ┆ 2    ┆ 2.2  │
│ B    ┆ 3    ┆ 3.3  │
│ B    ┆ 4    ┆ 4.4  │
│ C    ┆ 5    ┆ -1.1 │
│ C    ┆ 6    ┆ -2.2 │
│ C    ┆ 7    ┆ -3.3 │
│ D    ┆ 8    ┆ inf  │
│ F    ┆ 9    ┆ NaN  │
│ null ┆ null ┆ null │
└──────┴──────┴──────┘
>>>
>>> tf.group_by("ss").min()
>>>
┌──────┬──────┬──────┐
│ ss   ┆ u    ┆ ff   │
│ ---  ┆ ---  ┆ ---  │
│ str  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ null ┆ null ┆ null │
│ A    ┆ 1    ┆ 1.1  │
│ B    ┆ 0    ┆ 0.0  │
│ C    ┆ 5    ┆ -3.3 │
│ D    ┆ 8    ┆ inf  │
│ F    ┆ 9    ┆ NaN  │
└──────┴──────┴──────┘
n_unique() TdLazyFrame[source]#

Aggregation operation that counts the unique values of the given column in the group for of all the non group by columns.

Examples:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┬──────┐
│ ss   ┆ u    ┆ ff   │
│ ---  ┆ ---  ┆ ---  │
│ str  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ A    ┆ 1    ┆ 1.1  │
│ B    ┆ 0    ┆ 0.0  │
│ A    ┆ 2    ┆ 2.2  │
│ B    ┆ 3    ┆ 3.3  │
│ B    ┆ 4    ┆ 4.4  │
│ C    ┆ 5    ┆ -1.1 │
│ C    ┆ 6    ┆ -2.2 │
│ C    ┆ 7    ┆ -3.3 │
│ D    ┆ 8    ┆ inf  │
│ F    ┆ 9    ┆ NaN  │
│ null ┆ null ┆ null │
└──────┴──────┴──────┘
>>>
>>> tf.group_by("ss").n_unique()
>>>
┌──────┬─────┬─────┐
│ ss   ┆ u   ┆ ff  │
│ ---  ┆ --- ┆ --- │
│ str  ┆ u32 ┆ u32 │
╞══════╪═════╪═════╡
│ null ┆ 1   ┆ 1   │
│ A    ┆ 2   ┆ 2   │
│ B    ┆ 3   ┆ 3   │
│ C    ┆ 3   ┆ 3   │
│ D    ┆ 1   ┆ 1   │
│ F    ┆ 1   ┆ 1   │
└──────┴─────┴─────┘
sum() TdLazyFrame[source]#

Aggregation operation that computes the sum for all values in the group for of all the non group by columns.

Examples:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┬──────┐
│ ss   ┆ u    ┆ ff   │
│ ---  ┆ ---  ┆ ---  │
│ str  ┆ i64  ┆ f64  │
╞══════╪══════╪══════╡
│ A    ┆ 1    ┆ 1.1  │
│ B    ┆ 0    ┆ 0.0  │
│ A    ┆ 2    ┆ 2.2  │
│ B    ┆ 3    ┆ 3.3  │
│ B    ┆ 4    ┆ 4.4  │
│ C    ┆ 5    ┆ -1.1 │
│ C    ┆ 6    ┆ -2.2 │
│ C    ┆ 7    ┆ -3.3 │
│ D    ┆ 8    ┆ inf  │
│ F    ┆ 9    ┆ NaN  │
│ null ┆ null ┆ null │
└──────┴──────┴──────┘
>>>
>>> tf.group_by("ss").sum()
>>>
┌──────┬─────┬──────┐
│ ss   ┆ u   ┆ ff   │
│ ---  ┆ --- ┆ ---  │
│ str  ┆ i64 ┆ f64  │
╞══════╪═════╪══════╡
│ null ┆ 0   ┆ 0.0  │
│ A    ┆ 3   ┆ 3.3  │
│ B    ┆ 7   ┆ 7.7  │
│ C    ┆ 18  ┆ -6.6 │
│ D    ┆ 8   ┆ inf  │
│ F    ┆ 9   ┆ NaN  │
└──────┴─────┴──────┘