vastorbit.VastColumn.mode¶
- VastColumn.mode(dropna: bool = False, n: int = 1) Annotated[bool | float | str | timedelta | datetime, 'Python Scalar']¶
This function returns the nth most frequently occurring element in the VastColumn. It’s a practical method for identifying the element with a specific rank in terms of its occurrence frequency within the column. For example, you can use this function to find the third, fifth, or any other desired most frequent element.
Warning
This function first groups the data by a specific column, then computes the count of each group, and finally applies filtering. It’s important to note that this operation can be computationally expensive, especially for datasets with a large cardinality.
- Parameters:
dropna (bool, optional) – If set to True, NULL values are not considered during the computation.
n (int, optional) – Integer corresponding to the offset. For example, if n = 1, this method returns the mode of the VastColumn.
- Returns:
VastColumn nth most occurent element.
- Return type:
PythonScalar
Examples
For this example, let’s generate a dataset and calculate the mode of a column:
import vastorbit as vo data = vo.VastFrame( { "x": [1, 2, 4, 9, 10, 15, 20, 22], "y": [1, 2, 1, 2, 1, 1, 2, 1], "z": [10, 12, 2, 1, 9, 8, 1, 3], } ) data["y"].mode()
Let’s now return the second most frequent element:
data["y"].mode(n = 2)
Note
All the calculations are pushed to the database.
Hint
For more precise control, please refer to the
aggregatemethod.See also
VastColumn.mean(): Mean for a specific column.VastFrame.median(): Median for particular columns.