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
A | B | C | ||
---|---|---|---|---|
int32 | int32 | int32 | ||
0 | 1 | NA | 1 | |
1 | 1 | 2 | 2 | |
2 | 2 | 3 | 1 | |
3 | NA | 4 | 1 | |
4 | 1 | NA | 2 | |
5 | 2 | 5 | 4 |
Count the number of unique values for each column in the frame:
df[:, dt.nunique(f[:])]
A | B | C | ||
---|---|---|---|---|
int64 | int64 | int64 | ||
0 | 2 | 4 | 3 |
Count the number of unique values for column B
only:
df[:, dt.nunique(f.B)]
B | ||
---|---|---|
int64 | ||
0 | 4 |
The content on this page is licensed under the Creative Commons Attribution 4.0 License
(CC BY 4.0) ,
and code samples are licensed under the MIT License.