Loading...

vastorbit.VastColumn.nunique

VastColumn.nunique(approx: bool = True) int

When aggregating the VastFrame using nunique (cardinality), vastorbit employs the COUNT DISTINCT function to determine the number of unique values in particular columns. It also offers the option to use APPROX_DISTINCT, a more efficient approximation method for calculating cardinality.

Hint

This flexibility allows you to optimize the computation based on your specific requirements, keeping in mind that using APPROX_DISTINCT can significantly improve performance when cardinality estimation is sufficient for your analysis.

Important

To calculate the exact cardinality of a column, you should set the parameter approx to False. This will ensure that the cardinality is computed accurately rather than using the approximate method.

Parameters:

approx (bool, optional) – If set to True, the approximate cardinality is returned. By setting this parameter to False, the function’s performance can drastically decrease.

Returns:

VastColumn cardinality (or approximate cardinality).

Return type:

int

Examples

For this example, let’s generate a dataset and calculate the cardinality 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"].nunique()

Note

All the calculations are pushed to the database.

Hint

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

See also

VastColumn.aggregate() : Aggregations for a specific column.
VastFrame.aggregate() : Aggregates for particular columns.