Loading...

verticapy.vDataColumn.value_counts#

vDataColumn.value_counts(k: int = 30) TableSample#

This function returns the k most frequently occurring elements in a column, along with information about how often they occur. Additionally, it provides various statistical details to give you a comprehensive view of the data distribution.

Parameters#

k: int, optional

Number of most occurent elements to return.

Returns#

TableSample

result.

Examples#

For this example, we will use the following dataset:

import verticapy as vp

data = vp.vDataFrame(
    {
        "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 values and counts for a specific column.

data["x"].value_counts(k = 6)
value
name"x"
dtypeinteger
unique8.0
count8.0
91
101
11
41
21
151
Others1

Note

All the calculations are pushed to the database.

Hint

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

See also

vDataColumn.nunique() : Cardinality for a specific column.
vDataFrame.duplicated() : Duplicated values for particular columns.