TableApplication(function, columns)
Source¶
A function applied to each value of columns of a Table, used by Table.apply.
Each column is replaced at its place, under its name. A missing value stays missing, and an integer or boolean
column keeps its type when a ValueMapping gives it missing values.
Added in version 0.2.0
Parameters:
-
function(MathFunction | TimeFunction | ValueMapping)A
MathFunction, such asndp.SquareRoot(), aTimeFunction, such asndp.DatePart(unit=ndp.DatePartUnit.MONTH), or aValueMapping, asArray.applytakes. -
columns(list[str])The names of the columns, at least one, each once. The application keeps its own copy of the list.
Raises:
-
InvalidTypeErrorWhen a setting is not of the type its annotation names.
-
EmptyListErrorWhen
columnsis an empty list. -
InvalidColumnNameErrorWhen a column name is an empty text.
-
DuplicateColumnErrorWhen a column name appears twice.
Examples:
import numdaplot as ndp
first_answers = ndp.Array.from_list([1, 7, 2])
second_answers = ndp.Array.from_list([9, 3, 1])
survey = ndp.Table.from_arrays({"q1": first_answers, "q2": second_answers})
unknown_answers = [ndp.ValueChange(7, None), ndp.ValueChange(9, None)]
mapping = ndp.ValueMapping(changes=unknown_answers, others=ndp.Unmatched.KEEP)
survey.apply(ndp.TableApplication(function=mapping, columns=["q1", "q2"]))
# q1 q2
# INT64 INT64
# 0 1 <NA>
# 1 <NA> 3
# 2 2 1