datatable.count()¶
Count non-missing values for each column from cols. When called
with no arguments, simply count the number of rows. This function
is group-aware.
Parameters¶
cols
FExprInput columns if any.
return
FExprf-expression that counts the number of non-missing values
for each column from cols. If cols is not provided,
it calculates the number of rows. The returned f-expression
has as many rows as there are groups, it also has the same names and
number of columns as in cols. All the resulting column’s stypes
are int64.
except
TypeErrorThe exception is raised when one of the input columns has
an obj64 type.
Examples¶
from datatable import dt, f
DT = dt.Frame({'A': [None, 1, 2, None, 2],
'B': [None, 2, 3, 4, 5],
'C': [1, 2, 1, 1, 2]})
DT
| A | B | C | ||
|---|---|---|---|---|
| int32 | int32 | int32 | ||
| 0 | NA | NA | 1 | |
| 1 | 1 | 2 | 2 | |
| 2 | 2 | 3 | 1 | |
| 3 | NA | 4 | 1 | |
| 4 | 2 | 5 | 2 |
Count non-missing values in all the columns:
DT[:, dt.count(f[:])]
| A | B | C | ||
|---|---|---|---|---|
| int64 | int64 | int64 | ||
| 0 | 3 | 4 | 5 |
Count non-missing values in the column B only:
DT[:, dt.count(f.B)]
| B | ||
|---|---|---|
| int64 | ||
| 0 | 4 |
Get the number of rows in a frame:
DT[:, dt.count()]
| count | ||
|---|---|---|
| int64 | ||
| 0 | 5 |
See Also¶
countna()– function to count the number of missing values.
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.