datatable.prod()¶
Added in version 1.1.0
Calculate the product of values for each column from cols. The product
of missing values is calculated as one.
Parameters¶
cols
FExprInput columns.
return
FExprf-expression having one row, and the same names and number of columns
as in cols. The column stypes are int64 for
boolean and integer columns, float32 for float32 columns
and float64 for float64 columns.
except
TypeErrorThe exception is raised when one of the columns from cols
has a non-numeric type.
Examples¶
from datatable import dt, f, by, prod
DT = dt.Frame({'A': [1, 1, 2, 1, 2],
'B': [None, 2, 3, 4, 5],
'C': [1, 2, 1, 1, 2]})
DT
| A | B | C | ||
|---|---|---|---|---|
| int32 | int32 | int32 | ||
| 0 | 1 | NA | 1 | |
| 1 | 1 | 2 | 2 | |
| 2 | 2 | 3 | 1 | |
| 3 | 1 | 4 | 1 | |
| 4 | 2 | 5 | 2 |
Get the product for column A:
DT[:, prod(f.A)]
| A | ||
|---|---|---|
| int64 | ||
| 0 | 4 |
Get the product for multiple columns:
DT[:, prod(f['A', 'B'])]
| A | B | ||
|---|---|---|---|
| int64 | int64 | ||
| 0 | 4 | 120 |
In the presence of by(), it returns the product of the specified columns per group:
DT[:, prod(f['A', 'B']), by('C')]
| C | A | B | ||
|---|---|---|---|---|
| int32 | int64 | int64 | ||
| 0 | 1 | 2 | 12 | |
| 1 | 2 | 2 | 10 |
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.