Loading...

vastorbit.VastColumn.topk

VastColumn.topk(k: int = -1, dropna: bool = True) TableSample

This function returns the k most frequently occurring elements in a column, along with their distribution expressed as percentages. It’s a useful tool for understanding the composition of your data and identifying the most prominent elements.

Parameters:
  • k (int, optional) – Number of most occurent elements to return.

  • dropna (bool, optional) – If set to True, NULL values are not considered during the computation.

Returns:

result.

Return type:

TableSample

Examples

For this example, we will use the following dataset:

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],
    }
)

Now, let’s calculate the top k values for a specific column.

data["x"].topk()
countpercent
2112.5
22112.5
15112.5
10112.5
9112.5
4112.5
20112.5
1112.5
Rows: 1-8 | Columns: 3

Note

All the calculations are pushed to the database.

Hint

For more precise control, please refer to the aggregate method.

See also

VastColumn.nunique() : Cardinality for a specific column.
VastFrame.nunique() : Cardinality for particular columns.