withNumeric method
DataFrame
withNumeric({
- required String name,
- required NumericColumn column,
- bool ignoreLengthMismatch = false,
A new data frame with a numeric column added.
Example:
final d = """
a
1
2
3
""".parseAsCsv();
print(d);
print(d.withNumeric(
name: "b",
column: NumericColumn([3, 4, 5]),
));
.-.
|a|
:-:
|1|
|2|
|3|
'-'
.-.-.
|a|b|
:-+-:
|1|3|
|2|4|
|3|5|
'-'-'
Implementation
DataFrame withNumeric({
required String name,
required NumericColumn column,
bool ignoreLengthMismatch = false,
}) {
if (!_columnNameOkay(name)) {
throw PackhorseError.badColumnName(name);
}
if (!ignoreLengthMismatch && column.length != rowNumber) {
throw PackhorseError.badStructure(
"Adding column of length ${column.length} to data frame"
"with $rowNumber rows.");
}
return copy..numericColumns[name] = column;
}