datatable.nunique()

Added in version 1.1.0

Count the number of unique values for each column from cols.

Parameters

cols
FExpr

Input columns.

return
Expr

f-expression having one row, and the same names and number of columns as in cols. All the returned column stypes are int64.

except
TypeError

The exception is raised when one of the columns from cols has an unsupported type, e.g. obj64.

Examples

from datatable import dt, f df = dt.Frame({'A': [1, 1, 2, None, 1, 2], 'B': [None, 2, 3, 4, None, 5], 'C': [1, 2, 1, 1, 2, 4]}) df
ABC
int32int32int32
01NA1
1122
2231
3NA41
41NA2
5254

Count the number of unique values for each column in the frame:

df[:, dt.nunique(f[:])]
ABC
int64int64int64
0243

Count the number of unique values for column B only:

df[:, dt.nunique(f.B)]
B
int64
04