datatable.rowsum()¶
For each row, calculate the sum of all values in cols
. Missing values
are treated as if they are zeros and skipped during the calcultion.
Parameters¶
cols
FExpr
Input columns.
except
TypeError
The exception is raised when one of the columns from cols
has a non-numeric type.
Examples¶
from datatable import dt, f, rowsum
DT = dt.Frame({'a': [1,2,3],
'b': [2,3,4],
'c':['dd','ee','ff'],
'd':[5,9,1]})
DT
a | b | c | d | ||
---|---|---|---|---|---|
int32 | int32 | str32 | int32 | ||
0 | 1 | 2 | dd | 5 | |
1 | 2 | 3 | ee | 9 | |
2 | 3 | 4 | ff | 1 |
DT[:, rowsum(f[int])]
C0 | ||
---|---|---|
int32 | ||
0 | 8 | |
1 | 14 | |
2 | 8 |
DT[:, rowsum(f.a, f.b)]
C0 | ||
---|---|---|
int32 | ||
0 | 3 | |
1 | 5 | |
2 | 7 |
The above code could also be written as
DT[:, f.a + f.b]
C0 | ||
---|---|---|
int32 | ||
0 | 3 | |
1 | 5 | |
2 | 7 |
See Also¶
rowcount()
– count non-missing values row-wise.
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.