withNumericColumnFromRowValues method
A new data frame with a numeric column calculated from row values.
Example:
final d = """
number,base
FF,16
33,4
AA,12
10201,3
""".parseAsCsv(types: {"number": ColumnType.categoric});
print(d);
print(d.withNumericColumnFromRowValues(
name: "decimal",
generator: (numeric, categoric) => int.tryParse(
categoric["number"]!,
radix: numeric["base"]!.toInt(),
)! as num,
));
.----.-------.
|base|number |
:----+-------:
|16 |FF |
|4 |33 |
|12 |AA |
|3 |10201 |
'----'-------'
.----.-------.-------.
|base|decimal|number |
:----+-------+-------:
|16 |255 |FF |
|4 |15 |33 |
|12 |130 |AA |
|3 |100 |10201 |
'----'-------'-------'
Implementation
DataFrame withNumericColumnFromRowValues({
required String name,
required num Function(
Map<String, num> numericValues, Map<String, String> categoricValues)
generator,
}) {
if (!_columnNameOkay(name)) {
throw PackhorseError.badColumnName(name);
}
return copy
..numericColumns[name] =
NumericColumn(_numericRowValueResults(generator));
}