Expr.List (ListOps)
Namespace: Polars.FSharp
Instance Methods
Agg
Run any polars aggregation expression against the list’ elements.
member Agg(expr: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
expr | Expr | Expression to run. Note that you can select an element with Pl.Element(). |
All
Evaluate whether all boolean values in a list are true.
member All(?ignoreNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
ignoreNulls | bool (optional) | - |
Any
Evaluate whether any boolean value in a list is true.
member Any(?ignoreNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
ignoreNulls | bool (optional) | - |
ArgMax
Retrieve the index of the maximum value in every sublist.
member ArgMax : unit -> ExprArgMin
Retrieve the index of the minimum value in every sublist.
member ArgMin : unit -> ExprConcat
Combine the current expression with other expressions into a List. Result: [parent_val, other_val_1, other_val_2, ...] Equivalent to: pl.concatList([parent, others...])
Overload: Concat a single expression/column.
member Concat(others: seq<'b>) : Expr
member Concat(other: 'a) : ExprParameters
| Name | Type | Description |
|---|---|---|
others | seq<'b> | - |
other | 'a | - |
Contains
Check if the list contains the given item.
member Contains(item: Expr, ?nullsEqual: bool) : Expr
member Contains(item: int, ?nullsEqual: bool) : Expr
member Contains(item: string, ?nullsEqual: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
item | Expr / int / string | - |
nullsEqual | bool (optional) | - |
Diff
Calculate the first discrete difference between shifted items of every sublist.
member Diff(?n: int64, ?nullBehavior: NullBehavior) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | int64 (optional) | Number of slots to shift. |
nullBehavior | NullBehavior (optional) | How to handle null values. |
DropNulls
Drop all null values in the list. The original order of the remaining elements is preserved.
member DropNulls : unit -> ExprEval
Run any polars expression against the lists’ elements.
member Eval(expr: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
expr | Expr | Expression to run. Note that you can select an element with Pl.Element(). |
Explode
Explode a list expression.
This turns a list column into a long column (flattening).
Warning: When used in DataFrame.Select with other columns, it may cause a length mismatch error if the other columns are not broadcasted. Use DataFrame.Explode for safely exploding columns while repeating others.
member Explode(?emptyAsNull: bool, ?keepNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
emptyAsNull | bool (optional) | - |
keepNulls | bool (optional) | - |
First
Get the first element of the list.
member First : unit -> ExprGather
Take sublists by multiple indices.The indices may be defined in a single column, or by sublists in another column of dtype List.
member Gather(indices: Expr, ?nullOnOob: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
indices | Expr | Indices to return per sublist |
nullOnOob | bool (optional) | Behavior if an index is out of bounds: True -> set as null False -> raise an error Note that defaulting to raising an error is much cheaper |
GatherEvery
Take every n-th value start from offset in sublists.
member GatherEvery(n: Expr, ?offset: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | Expr | Gather every n-th element. |
offset | Expr (optional) | Starting Index |
Get
Get element at index.
member Get(index: int, ?nullOnOob: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
index | int | - |
nullOnOob | bool (optional) | - |
Head
Slice the first n values of every sublist.
member Head(?n: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | Expr (optional) | Number of values to return for each sublist. |
Join
Join list elements with separator.
member Join(separator: string, ?ignoreNulls: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
separator | string | - |
ignoreNulls | bool (optional) | - |
Last
Get the Last element of the list.
member Last : unit -> ExprLen
Return the number of elements in each list.
member Len : unit -> ExprMax
Calculate the max of the list elements.
member Max : unit -> ExprMean
Calculate the mean of the list elements.
member Mean : unit -> ExprMedian
Calculate the median of the list elements.
member Median : unit -> ExprMin
Calculate the min of the list elements.
member Min : unit -> ExprNUnique
Count the number of unique values in every sub-lists.
member NUnique : unit -> ExprReverse
Reverse the list.
member Reverse : unit -> ExprSampleFrac
Sample from this list.
member SampleFrac(
fraction: Expr,
?withReplacement: bool,
?shuffle: bool,
?seed: uint64
) : ExprParameters
| Name | Type | Description |
|---|---|---|
fraction | Expr | Fraction of items to return. |
withReplacement | bool (optional) | Allow values to be sampled more than once. |
shuffle | bool (optional) | Shuffle the order of sampled data points. |
seed | uint64 (optional) | Seed for the random number generator. If set to None (default), a random seed is generated for each sample operation. |
SampleN
Sample from this list.
member SampleN(
?n: Expr,
?withReplacement: bool,
?shuffle: bool,
?seed: uint64
) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | Expr (optional) | Number of items to return.Defaults to 1 |
withReplacement | bool (optional) | Allow values to be sampled more than once. |
shuffle | bool (optional) | Shuffle the order of sampled data points. |
seed | uint64 (optional) | Seed for the random number generator. If set to None (default), a random seed is generated for each sample operation. |
SetDifference
Compute the SET DIFFERENCE between the elements in this list and the elements of other.
member SetDifference(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | Right hand side of the set operation. |
SetIntersection
Compute the SET INTERSECTION between the elements in this list and the elements of other.
member SetIntersection(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | Right hand side of the set operation. |
SetSymmetricDifference
Compute the SET SYMMETRIC DIFFERENCE between the elements in this list and the elements of other.
member SetSymmetricDifference(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | Right hand side of the set operation. |
SetUnion
Compute the SET UNION between the elements in this list and the elements of other.
member SetUnion(other: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
other | Expr | Right hand side of the set operation. |
Shift
Shift list values by the given number of indices.
member Shift(?n: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | Expr (optional) | Number of indices to shift forward. If a negative value is passed, values are shifted in the opposite direction instead. |
Slice
Slice every sublist.
member Slice(offset: Expr, ?length: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
offset | Expr | Start index. Negative indexing is supported. |
length | Expr (optional) | Length of the slice. If null, the slice is taken to the end of the list. |
Sort
Sort the lists in this column.
member Sort(?descending: bool, ?nullsLast: bool, ?maintainOrder: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
descending | bool (optional) | Sort in descending order. |
nullsLast | bool (optional) | Place null values last. |
maintainOrder | bool (optional) | - |
Std
Get the standard deviation.
member Std(?ddof: byte) : ExprParameters
| Name | Type | Description |
|---|---|---|
ddof | byte (optional) | “Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of elements. By default ddof is 1. |
Sum
Calculate the sum of the values in the list (row-wise).
member Sum : unit -> ExprTail
Slice the last n values of every sublist.
member Tail(?n: Expr) : ExprParameters
| Name | Type | Description |
|---|---|---|
n | Expr (optional) | Number of values to return for each sublist. |
ToArray
Convert a List column into an Array column with the same inner data type.
member ToArray(width: int64) : ExprParameters
| Name | Type | Description |
|---|---|---|
width | int64 | Width of the resulting Array column. |
ToStruct
Convert the list to a struct type with explicitly named fields.
Convert the list to a struct type using a function to generate field names.
Convert the list to a struct type up to a maximum number of fields, using default naming ("field_0", "field_1", ...).
member ToStruct(fields: seq<string>) : Expr
member ToStruct(nameGenerator: (int -> string), fieldCount: int) : Expr
member ToStruct(upperBound: int) : ExprParameters
| Name | Type | Description |
|---|---|---|
fields | seq<string> | A sequence of names for the struct fields. |
nameGenerator | (int -> string) | A function that takes a field index and returns the field name. |
fieldCount | int | The number of struct fields to create. |
upperBound | int | The maximum number of struct fields to create. Used for compile-time schema inference. |
Returns: A new Expr representing the struct conversion.
Unique
Get the unique/distinct values in the list.
member Unique(?maintainOrder: bool) : ExprParameters
| Name | Type | Description |
|---|---|---|
maintainOrder | bool (optional) | Maintain order of data. This requires more work. |
Var
Get the variance.
member Var(?ddof: byte) : ExprParameters
| Name | Type | Description |
|---|---|---|
ddof | byte (optional) | “Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of elements. By default ddof is 1. |